Check if sum of the given array can be reduced to 0 by reducing array elements by K | Function to check if the sum can be made 0 or not ; Stores sum of array elements ; Traverse the array ; Driver Code ; Given array arr
function sumzero ( arr , N , K ) { var sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 0 ) document . write ( " " ) ; else if ( sum > 0 ) { if ( sum % K == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } else document . write ( " " ) ; return 0 ; } var K , N ; var arr1 = [ 1 , - 6 , 2 , 2 ] ; K = 1 ; N = arr1 . length ; sumzero ( arr1 , N , K ) ;