human
Divide N segments into two non | Function to print the answer if it exists using the concept of merge overlapping segments.
Sort the indices based on their corresponding value in V.
Resultant array Initialise all the values in resultant array with '2' except the first index of ' indices ' which is initialised as '1' Initialise maxR to store the maximum of all right values encountered so far.
If the i - th index has any any point in common with the ( i - 1 ) th index classify it as '1' in resultant array and update maxR if necessary else we have found the breakpoint and we can exit the loop.
Driver Code"
Solution in Python:
assistant
#Here is code to divide N segments into two non and the other steps required.
 def printAnswer ( v , n ) :
	indices = list ( range ( n ) )
	indices . sort ( key = lambda i : v [ i ] )
	res = [ 2 ] * n
	res [ indices [ 0 ] ] = 1
	maxR = v [ indices [ 0 ] ] [ 1 ]
	for i in range ( 1 , n ) :
		if maxR >= v [ indices [ i ] ] [ 0 ] :
			res [ indices [ i ] ] = res [ indices [ i - 1 ] ]
			maxR = max ( maxR , v [ indices [ i ] ] [ 1 ] )
		else :
			break
	else :
		print ( " Not ▁ possible " )
		return
	print ( " ▁ " . join ( map ( str , res ) ) )
if __name__ == " _ _ main _ _ " :
	v = [ [ 2 , 8 ] , [ 3 , 4 ] , [ 5 , 8 ] , [ 9 , 10 ] ]
	n = len ( v )
	printAnswer ( v , n )