Job Scheduling with two jobs allowed at a time | Python3 program to check if all jobs can be scheduled if two jobs are allowed at a time . ; making a pair of starting and ending time of job ; sorting according to starting time of job ; starting first and second job simultaneously ; Checking if starting time of next new job is greater than ending time of currently scheduled first job ; Checking if starting time of next new job is greater than ending time of ocurrently scheduled second job ; Driver Code ; startin = [ 1 , 2 , 4 ] starting time of jobs endin = [ 2 , 3 , 5 ] ending times of jobs
def checkJobs ( startin , endin , n ) : NEW_LINE INDENT a = [ ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT a . append ( [ startin [ i ] , endin [ i ] ] ) NEW_LINE DEDENT a . sort ( ) NEW_LINE tv1 = a [ 0 ] [ 1 ] NEW_LINE tv2 = a [ 1 ] [ 1 ] NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( a [ i ] [ 0 ] >= tv1 ) : NEW_LINE INDENT tv1 = tv2 NEW_LINE tv2 = a [ i ] [ 1 ] NEW_LINE DEDENT elif ( a [ i ] [ 0 ] >= tv2 ) : NEW_LINE INDENT tv2 = a [ i ] [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT return 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( checkJobs ( startin , endin , n ) ) NEW_LINE DEDENT