Question 2 - Optimized

mail@pastecode.io avatar
unknown
python
2 months ago
998 B
8
Indexable
Never
def earliest_finish_time(comedy_release, comedy_duration, drama_release, drama_duration):
    # Combine comedy and drama movies along with their release times and durations
    events = [(time, 'comedy', duration) for time, duration in zip(comedy_release, comedy_duration)] + \
             [(time, 'drama', duration) for time, duration in zip(drama_release, drama_duration)]

    # Sort events by release time
    events.sort()

    # Initialize variables to track the earliest finish time
    earliest_time = float('inf')
    comedy_end_time = drama_end_time = 0

    # Iterate through all events
    for release_time, category, duration in events:
        if category == 'comedy':
            comedy_end_time = max(comedy_end_time, release_time) + duration
        else:
            drama_end_time = max(drama_end_time, release_time) + duration

        # Update the earliest finish time
        earliest_time = min(earliest_time, max(comedy_end_time, drama_end_time))

    return earliest_time
Leave a Comment