human
Find Intersection of all Intervals | Function to print the intersection.
First interval.
Check rest of the intervals and find the intersection.
If no intersection exists.
Else update the intersection.
Driver code"
How can the above be solved in Python?
 Write me a code to find Intersection of all Intervals and the other steps required?
assistant
#Here is code to find Intersection of all Intervals and the other steps required.
 def findIntersection ( intervals , N ) :
	l = intervals [ 0 ] [ 0 ]
	r = intervals [ 0 ] [ 1 ]
	for i in range ( 1 , N ) :
		if ( intervals [ i ] [ 0 ] > r or intervals [ i ] [ 1 ] < l ) :
			print ( - 1 )
		else :
			l = max ( l , intervals [ i ] [ 0 ] )
			r = min ( r , intervals [ i ] [ 1 ] )
	print ( " [ " , l , " , ▁ " , r , " ] " )
intervals = [ [ 1 , 6 ] , [ 2 , 8 ] , [ 3 , 10 ] , [ 5 , 8 ] ]
N = len ( intervals )
findIntersection ( intervals , N )