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
def findPair ( arr , N ) : NEW_LINE INDENT arr . sort ( key = lambda x : x [ 0 ] ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT b = arr [ i - 1 ] [ 1 ] NEW_LINE d = arr [ i ] [ 1 ] NEW_LINE if ( b > d ) : NEW_LINE INDENT print ( " ( " , arr [ i - 1 ] [ 0 ] , b , " ) , ▁ ( " , arr [ i ] [ 0 ] , d , " ) " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " NO SUCH PAIR EXIST " ) ; NEW_LINE DEDENT arr = [ [ 3 , 7 ] , [ 21 , 23 ] , [ 4 , 13 ] , [ 1 , 2 ] , [ 7 , - 1 ] ] NEW_LINE findPair ( arr , 5 ) NEW_LINE