Count the number of unordered triplets with elements in increasing order and product less than or equal to integer X | C # implementation to count the number of unordered triplets such that the numbers are in increasing order and the product of them is less than or equal to integer X ; Function to count the number of triplets ; Iterate through all the triplets ; Rearrange the numbers in ascending order ; Check if the necessary conditions satisfy ; Increment count ; Return the answer ; Driver code
using System ; class GFG { static int countTriplets ( int [ ] a , int n , int x ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { int [ ] temp = { a [ i ] , a [ j ] , a [ k ] } ; Array . Sort ( temp ) ; if ( temp [ 0 ] < temp [ 1 ] && temp [ 1 ] < temp [ 2 ] && temp [ 0 ] * temp [ 1 ] * temp [ 2 ] <= x ) answer ++ ; } } } return answer ; } public static void Main ( ) { int [ ] A = { 3 , 2 , 5 , 7 } ; int N = A . Length ; int X = 42 ; Console . WriteLine ( countTriplets ( A , N , X ) ) ; } }