Count of index pairs in array whose range product is a positive integer | Javascript 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
function positiveProduct ( arr , n ) { let even_count = 0 ; let odd_count = 0 ; let total_count = 0 ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( total_count % 2 == 0 ) { even_count ++ ; } else { odd_count ++ ; } if ( arr [ i ] < 0 ) { total_count ++ ; } if ( total_count % 2 == 0 ) ans += even_count ; else ans += odd_count ; } document . write ( ans ) ; } let A = [ 5 , - 3 , 3 , - 1 , 1 ] ; let size = A . length ; positiveProduct ( A , size ) ;