Insert the end day of the jobs which can be completed on i - th day in a priority queue
while ( index < len ( ranges ) and ranges [ index ] [ 0 ] <= i ) : NEW_LINE INDENT queue . append ( ranges [ index ] [ 1 ] ) NEW_LINE index += 1 NEW_LINE DEDENT queue . sort ( ) NEW_LINE