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
for i in range ( 1 , n ) : NEW_LINE INDENT if maxR >= v [ indices [ i ] ] [ 0 ] : NEW_LINE INDENT res [ indices [ i ] ] = res [ indices [ i - 1 ] ] NEW_LINE maxR = max ( maxR , v [ indices [ i ] ] [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " Not ▁ possible " ) NEW_LINE return NEW_LINE DEDENT print ( " ▁ " . join ( map ( str , res ) ) ) NEW_LINE