Count of pairs ( x , y ) in an array such that x < y | Java implementation of the approach ; Function to return the number of pairs ( x , y ) such that x < y ; Length of the array ; Calculate the number of valid pairs ; Return the count of valid pairs ; Driver code
class GFG { static int getPairs ( int a [ ] ) { int n = a . length ; int count = ( n * ( n - 1 ) ) / 2 ; return count ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 4 , 3 , 1 } ; System . out . println ( getPairs ( a ) ) ; } }