Function to find two pairs ( a , b ) and ( c , d ) such that a < c and b > d
function findPair ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let a = arr [ i ] . first , b = arr [ i ] . second ; for ( let j = i + 1 ; j < N ; j ++ ) { let c = arr [ j ] . first , d = arr [ j ] . second ; if ( a < c && b > d ) { document . write ( " " + a + " " + b + " " + c + " " + d + " " ) ; return ; } } }