Count ways to obtain triplets with positive product consisting of at most one negative element | Java Program to implement the above approach ; 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
import java . util . * ; class GFG { static int possibleTriplets ( int arr [ ] , int N ) { int freq = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { freq ++ ; } } return ( int ) ( ( freq * 1L * ( freq - 1 ) * ( freq - 2 ) ) / 6 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , - 9 , - 3 , 6 } ; int N = arr . length ; System . out . print ( possibleTriplets ( arr , N ) ) ; } }