Find any two pairs ( a , b ) and ( c , d ) such that a d | Function to find two pairs ( a , b ) and ( c , d ) such that a < c and b > d ; Sort the array in increasing order of first element of pairs ; Traverse the array ; If no such pair found ; Driver Code
function findPair ( arr , N ) { arr . sort ( function ( a , b ) { return ( a [ 0 ] - b [ 0 ] ) || ( a [ 1 ] - b [ 1 ] ) ; } ) ; for ( let i = 1 ; i < N ; i ++ ) { let b = arr [ i - 1 ] [ 1 ] ; let d = arr [ i ] [ 1 ] ; if ( b > d ) { console . log ( " " + arr [ i - 1 ] [ 0 ] + " " + b + " " + arr [ i ] [ 0 ] + " " + d + " " ) ; return ; } } console . log ( " " ) ; } var arr = [ [ 3 , 7 ] , [ 21 , 23 ] , [ 4 , 13 ] , [ 1 , 2 ] , [ 7 , - 1 ] ] findPair ( arr , 5 ) ;