Two Genre Watch Finish
MediumScheduling · Amazon
You want to watch exactly one comedy and exactly one drama, one after the other, in either order.
Comedy i becomes available at time comedy_release[i] and lasts comedy_duration[i]. Drama j becomes available at time drama_release[j] and lasts drama_duration[j].
You can start the first title at its release time. The second title starts as soon as the first one is finished and the second title has been released, whichever is later. Titles cannot be paused or overlapped.
Return the earliest time at which you can finish both titles.
Example 1
- Input:
- comedy_release = [2, 8], comedy_duration = [6, 1], drama_release = [0, 5], drama_duration = [3, 2]
- Output:
- 9
- Explanation
- Watch drama 0 from 0 to 3, then comedy 0 (released at 2) from 3 to 9. Watching comedy 1 second instead also ends at 9, because it is not released until 8. No pairing or order finishes before 9.
Example 2
- Input:
- comedy_release = [10], comedy_duration = [4], drama_release = [1], drama_duration = [20]
- Output:
- 25
- Explanation
- Comedy first ends at 14, but the drama then takes 20 more: 34. Drama first runs 1 to 21, and the comedy (released at 10) follows from 21 to 25.
Example 3
- Input:
- comedy_release = [0], comedy_duration = [5], drama_release = [5], drama_duration = [5]
- Output:
- 10
- Explanation
- Comedy first runs 0 to 5, and the drama is released exactly at 5, so it runs 5 to 10.
Constraints
1 <= comedy_release.length == comedy_duration.length <= 5 * 10^41 <= drama_release.length == drama_duration.length <= 5 * 10^40 <= release times <= 10^91 <= durations <= 10^9