Solution should work
unknown
python
7 months ago
1.3 kB
5
Indexable
Never
def earliest_finish_time(comedy_release, comedy_duration, drama_release, drama_duration): # Combine movie information into dictionaries for easier access comedies = {release: duration for release, duration in zip(comedy_release, comedy_duration)} dramas = {release: duration for release, duration in zip(drama_release, drama_duration)} # Track earliest finish time for each combination of starting movie (comedy/drama) earliest_finish = float('inf') # Initialize with positive infinity # Find the earliest time to finish watching one movie from each category for release_time in sorted(comedies.keys() | dramas.keys()): # Combine all release times and sort them if release_time in comedies: comedy_end_time = release_time + comedies[release_time] if comedy_end_time in dramas: earliest_finish = min(earliest_finish, max(comedy_end_time, drama_release[drama_release.index(comedy_end_time)] + dramas[comedy_end_time])) if release_time in dramas: drama_end_time = release_time + dramas[release_time] if drama_end_time in comedies: earliest_finish = min(earliest_finish, max(drama_end_time, comedy_release[comedy_release.index(drama_end_time)] + comedies[drama_end_time])) return earliest_finish
Leave a Comment