Count of pairs ( x , y ) in an array such that x < y | C ++ implementation of the approach ; Function to return the number of pairs ( x , y ) such that x < y ; Length of the array ; Calculate the number valid pairs ; Return the count of valid pairs ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getPairs ( int a [ ] ) { int n = sizeof ( a [ 0 ] ) ; int count = ( n * ( n - 1 ) ) / 2 ; return count ; } int main ( ) { int a [ ] = { 2 , 4 , 3 , 1 } ; cout << getPairs ( a ) ; return 0 ; }