Check if all elements of the given array can be made 0 by decrementing value in pairs | Function to check if all the elements can be made 0 in an array ; Variable to store sum and maximum element in an array ; Loop to calculate the sum and max value of the given array ; If n is 1 or sum is odd or sum - max element < max then no solution ; For the remaining case , print Yes ; Driver code
function canMake ( n , ar ) { var sum = 0 , maxx = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; maxx = Math . max ( maxx , ar [ i ] ) ; } if ( n == 1 sum % 2 == 1 sum - maxx < maxx ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var n = 6 ; var arr = [ 1 , 1 , 2 , 3 , 6 , 11 ] ; canMake ( n , arr ) ;