human
What is a code to find a pair of overlapping intervals from a given Set and the other steps required given the following:
Find a pair of overlapping intervals from a given Set | Function to find a pair ( i , j ) such that i - th interval lies within the j - th interval.
Store interval and index of the interval in the form of { { l , r } , index }.
Traverse the array , arr [ ] [ ].
Stores l - value of the interval.
Stores r - value of the interval.
Push current interval and index into tup.
Sort the vector based on l - value of the intervals.
Stores r - value of current interval.
Stores index of current interval.
Traverse the vector , tup [ ].
Stores l - value of previous interval.
Stores l - value of current interval.
If Q and R are equal.
Print the index of interval.
Stores r - value of current interval.
If T is less than or equal to curr.
Update curr.
Update currPos.
If such intervals found.
Given l - value of segments.
Given r - value of segments.
Given size.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to find a pair of overlapping intervals from a given Set and the other steps required.
 def findOverlapSegement ( N , a , b ) :
	tup = [ ]
	for i in range ( N ) :
		x = a [ i ]
		y = b [ i ]
		tup . append ( ( ( x , y ) , i ) )
	tup . sort ( )
	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" , end = " " )
a = [ 1 , 2 , 3 , 2 , 2 ]
b = [ 5 , 10 , 10 , 2 , 15 ]
N = len ( a )
findOverlapSegement ( N , a , b )