Pair having all other given pairs lying between its minimum and maximum | Python3 program for the above approach ; Function to find the position of the pair that covers every pair in the array arr [ ] [ ] ; Position to store the index ; Stores the minimum second value ; Stores the maximum first value ; Iterate over the array of pairs ; Update right maximum ; Update left minimum ; Iterate over the array of pairs ; If any pair exists with value { left , right then store it ; Print the answer ; Driver Code ; Given array of pairs ; Function call
import sys NEW_LINE def position ( arr , N ) : NEW_LINE INDENT pos = - 1 NEW_LINE right = - sys . maxsize - 1 NEW_LINE left = sys . maxsize NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] [ 1 ] > right ) : NEW_LINE INDENT right = arr [ i ] [ 1 ] NEW_LINE DEDENT if ( arr [ i ] [ 0 ] < left ) : NEW_LINE INDENT left = arr [ i ] [ 0 ] NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] [ 0 ] == left and arr [ i ] [ 1 ] == right ) : NEW_LINE INDENT pos = i + 1 NEW_LINE DEDENT DEDENT print ( pos ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ [ 3 , 3 ] , [ 1 , 3 ] , [ 2 , 2 ] , [ 2 , 3 ] , [ 1 , 2 ] ] NEW_LINE N = len ( arr ) NEW_LINE position ( arr , N ) NEW_LINE DEDENT