Make the intervals non | Function to assign the intervals to two different processors ; Loop to pair the interval with their indices ; sorting the interval by their startb times ; Loop to iterate over the intervals with their start time ; Condition to check if there is a possible solution ; form = ''.join(form) ; Driver Code ; Function Call
def assignIntervals ( interval , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT interval [ i ] . append ( i ) NEW_LINE DEDENT interval . sort ( key = lambda x : x [ 0 ] ) NEW_LINE firstEndTime = - 1 NEW_LINE secondEndTime = - 1 NEW_LINE fin = ' ' NEW_LINE flag = False NEW_LINE for i in range ( n ) : NEW_LINE INDENT if interval [ i ] [ 0 ] >= firstEndTime : NEW_LINE INDENT firstEndTime = interval [ i ] [ 1 ] NEW_LINE interval [ i ] . append ( ' S ' ) NEW_LINE DEDENT elif interval [ i ] [ 0 ] >= secondEndTime : NEW_LINE INDENT secondEndTime = interval [ i ] [ 1 ] NEW_LINE interval [ i ] . append ( ' F ' ) NEW_LINE DEDENT else : NEW_LINE INDENT flag = True NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT form = [ ' ' ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT indi = interval [ i ] [ 2 ] NEW_LINE form [ indi ] = interval [ i ] [ 3 ] NEW_LINE DEDENT print ( form , " , ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT intervals = [ [ 360 , 480 ] , [ 420 , 540 ] , [ 600 , 660 ] ] NEW_LINE assignIntervals ( intervals , len ( intervals ) ) NEW_LINE DEDENT