Pair having all other given pairs lying between its minimum and maximum | Function to find the position of the pair that covers every pair in the array arr ; Stores the index of the resultant pair ; To count the occurences ; Iterate to check every pair ; Set count to 0 ; Condition to checked for overlapping of pairs ; If that pair can cover all other pairs then store its position ; If position not found ; Otherwise ; Driver Code ; Given array of pairs ; Function Call
def position ( arr , N ) : NEW_LINE INDENT pos = - 1 ; NEW_LINE count = 0 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT count = 0 ; NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( arr [ i ] [ 0 ] <= arr [ j ] [ 0 ] and arr [ i ] [ 1 ] >= arr [ j ] [ 1 ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT if ( count == N ) : NEW_LINE INDENT pos = i ; NEW_LINE DEDENT DEDENT if ( pos == - 1 ) : NEW_LINE INDENT print ( pos ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( pos + 1 ) ; NEW_LINE DEDENT 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