Find a pair of intersecting ranges from a given array | Function to find a pair of intersecting ranges ; Stores ending po of every range ; Stores the maximum ending poobtained ; Iterate from 0 to N - 1 ; Starting point of the current range ; End point of the current range ; Push pairs into tup ; Sort the tup vector ; Iterate over the ranges ; If starting points are equal ; Prthe indices of the intersecting ranges ; If no such pair of segments exist ; Driver Code ; Given N ; Given 2d ranges [ ] [ ] array ; Function call
def findIntersectingRange ( tup , N , ranges ) : NEW_LINE INDENT curr = 0 NEW_LINE currPos = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT x = ranges [ i ] [ 0 ] NEW_LINE y = ranges [ i ] [ 1 ] NEW_LINE tup . append ( [ [ x , y ] , i + 1 ] ) NEW_LINE DEDENT tup = sorted ( tup ) NEW_LINE curr = tup [ 0 ] [ 0 ] [ 1 ] NEW_LINE currPos = tup [ 0 ] [ 1 ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT Q = tup [ i - 1 ] [ 0 ] [ 0 ] NEW_LINE R = tup [ i ] [ 0 ] [ 0 ] NEW_LINE if ( Q == R ) : NEW_LINE INDENT if ( tup [ i - 1 ] [ 0 ] [ 1 ] < tup [ i ] [ 0 ] [ 1 ] ) : NEW_LINE INDENT print ( tup [ i - 1 ] [ 1 ] , tup [ i ] [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( tup [ i ] [ 1 ] , tup [ i - 1 ] [ 1 ] ) NEW_LINE DEDENT return NEW_LINE DEDENT T = tup [ i ] [ 0 ] [ 1 ] NEW_LINE if ( T <= curr ) : NEW_LINE INDENT print ( tup [ i ] [ 1 ] , currPos ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT curr = T NEW_LINE currPos = tup [ i ] [ 1 ] NEW_LINE DEDENT DEDENT print ( " - 1 ▁ - 1" ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 5 NEW_LINE ranges = [ [ 1 , 5 ] , [ 2 , 10 ] , [ 3 , 10 ] , [ 2 , 2 ] , [ 2 , 15 ] ] NEW_LINE findIntersectingRange ( [ ] , N , ranges ) NEW_LINE DEDENT