Number of subsequences with positive product | Function to return the count of all the subsequences with positive product ; To store the count of positive elements in the array ; To store the count of negative elements in the array ; If the current element is positive ; If the current element is negative ; For all the positive elements of the array ; For all the negative elements of the array ; For the empty subsequence ; Driver code
function cntSubSeq ( arr , n ) { let pos_count = 0 ; let neg_count = 0 ; let result ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = Math . pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= Math . pow ( 2 , neg_count - 1 ) ; result -= 1 ; return result ; } let arr = [ 2 , - 3 , - 1 , 4 ] ; let n = arr . length ; document . write ( cntSubSeq ( arr , n ) ) ;