Count of index pairs in array whose range product is a positive integer | Python3 program to find the count of index pairs in the array positive range product ; Condition if number of negative elements is even then increase even_count ; Otherwise increase odd_count ; Condition if current element is negative ; Condition if number of negative elements is even then add even_count in answer ; Otherwise add odd_count in answer ; Driver Code
def positiveProduct ( arr , n ) : NEW_LINE INDENT even_count = 0 NEW_LINE odd_count = 0 NEW_LINE total_count = 0 NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( total_count % 2 == 0 ) : NEW_LINE INDENT even_count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd_count += 1 NEW_LINE DEDENT if ( arr [ i ] < 0 ) : NEW_LINE INDENT total_count += 1 NEW_LINE DEDENT if ( total_count % 2 == 0 ) : NEW_LINE INDENT ans += even_count NEW_LINE DEDENT else : NEW_LINE INDENT ans += odd_count NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 5 , - 3 , 3 , - 1 , 1 ] NEW_LINE size = len ( A ) NEW_LINE positiveProduct ( A , size ) NEW_LINE DEDENT