Minimize increments or decrements required to make sum and product of array elements non | Function to find the sum of array ; Return the sum ; Function that counts the minimum operations required to make the sum and product of array non - zero ; Stores count of zero elements ; Iterate over the array to count zero elements ; Sum of elements of the array ; Print result ; Driver Code ; Given array arr [ ] ; Size of array ; Function Call
def array_sum ( arr , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += arr [ i ] NEW_LINE DEDENT return sum NEW_LINE DEDENT def countOperations ( arr , N ) : NEW_LINE INDENT count_zeros = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT count_zeros += 1 NEW_LINE DEDENT DEDENT sum = array_sum ( arr , N ) NEW_LINE if ( count_zeros ) : NEW_LINE INDENT return count_zeros NEW_LINE DEDENT if ( sum == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 1 , - 1 , 0 , 0 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countOperations ( arr , N ) ) NEW_LINE DEDENT