human
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"
How can the above be solved in Python?
assistant
#Here is code to find a pair of intersecting ranges from a given array and the other steps required.
 def findIntersectingRange ( tup , N , ranges ) :
	curr = 0
	currPos = 0
	for i in range ( N ) :
		x = ranges [ i ] [ 0 ]
		y = ranges [ i ] [ 1 ]
		tup . append ( [ [ x , y ] , i + 1 ] )
	tup = sorted ( tup )
	curr = tup [ 0 ] [ 0 ] [ 1 ]
	currPos = tup [ 0 ] [ 1 ]
	for i in range ( 1 , N ) :
		Q = tup [ i - 1 ] [ 0 ] [ 0 ]
		R = tup [ i ] [ 0 ] [ 0 ]
		if ( Q == R ) :
			if ( tup [ i - 1 ] [ 0 ] [ 1 ] < tup [ i ] [ 0 ] [ 1 ] ) :
				print ( tup [ i - 1 ] [ 1 ] , tup [ i ] [ 1 ] )
			else :
				print ( tup [ i ] [ 1 ] , tup [ i - 1 ] [ 1 ] )
			return
		T = tup [ i ] [ 0 ] [ 1 ]
		if ( T <= curr ) :
			print ( tup [ i ] [ 1 ] , currPos )
			return
		else :
			curr = T
			currPos = tup [ i ] [ 1 ]
	print ( " - 1 ▁ - 1" )
if __name__ == ' _ _ main _ _ ' :
	N = 5
	ranges = [ [ 1 , 5 ] , [ 2 , 10 ] , [ 3 , 10 ] , [ 2 , 2 ] , [ 2 , 15 ] ]
	findIntersectingRange ( [ ] , N , ranges )