human
Can you provide a code to maximal Disjoint Intervals and the other steps required given the following:
Maximal Disjoint Intervals | Function to find maximal disjoint set.
sort the list of intervals.
First interval will always be included in set.
End point of first interval.
Check if given interval overlap with previously included interval , if not then include this interval and update the end point of last added interval.
Driver code"
Solution in Python:
assistant
#Here is code to maximal Disjoint Intervals and the other steps required.
 def maxDisjointIntervals ( list_ ) :
	list_ . sort ( key = lambda x : x [ 1 ] )
	print ( " [ " , list_ [ 0 ] [ 0 ] , " , ▁ " , list_ [ 0 ] [ 1 ] , " ] " )
	r1 = list_ [ 0 ] [ 1 ]
	for i in range ( 1 , len ( list_ ) ) :
		l1 = list_ [ i ] [ 0 ]
		r2 = list_ [ i ] [ 1 ]
		if l1 > r1 :
			print ( " [ " , l1 , " , ▁ " , r2 , " ] " )
			r1 = r2
if __name__ == " _ _ main _ _ " :
	N = 4
	intervals = [ [ 1 , 4 ] , [ 2 , 3 ] , [ 4 , 6 ] , [ 8 , 9 ] ]
	maxDisjointIntervals ( intervals )