Count of distinct index pair ( i , j ) such that element sum of First Array is greater | function to find the number of pairs satisfying the given cond . ; Variables used for traversal ; count variable to store the count of possible pairs ; Nested loop to find out the possible pairs ; Check if the given condition is satisfied or not . If yes then increment the count . ; Return the count value ; Size of the arrays ; Initialise the arrays ; Function call that returns the count of possible pairs
function count_pairs ( a , b , N ) { let i , j ; let count = 0 ; for ( i = 0 ; i < ( N - 1 ) ; i ++ ) { for ( j = ( i + 1 ) ; j < N ; j ++ ) { if ( ( a [ i ] + a [ j ] ) > ( b [ i ] + b [ j ] ) ) { count ++ ; } } } return count ; } let N = 5 ; let a = [ 1 , 2 , 3 , 4 , 5 ] ; let b = [ 2 , 5 , 6 , 1 , 9 ] ; document . write ( count_pairs ( a , b , N ) ) ;