Count ways to obtain triplets with positive product consisting of at most one negative element | Function to calculate possible number of triplets ; counting frequency of positive numbers in array ; If current array element is positive ; Increment frequency ; Select a triplet from freq elements such that i < j < k . ; Driver Code
def possibleTriplets ( arr , N ) : NEW_LINE INDENT freq = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT freq += 1 NEW_LINE DEDENT DEDENT return ( freq * ( freq - 1 ) * ( freq - 2 ) ) // 6 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 5 , - 9 , - 3 , 6 ] NEW_LINE N = len ( arr ) NEW_LINE print ( possibleTriplets ( arr , N ) ) NEW_LINE DEDENT