Problem Β· Greedy
Minimum Time Spent π
Learn this problemProblem statement
Amazon Prime Video has movies in category 'comedy' or 'drama'. Determine the earliest time you can finish at least one movie from each category. The release schedule and duration of the movies are provided.
- You can start watching a movie at the time it is release or later.
- If you begin a movie at time t, it ends at t + duration.
- If a movie ends at time t + duration , the second movie can start at that time, t+ duration, or later.
- The movies can be watched in any order.
Complete the function minimumTimeSpent which has the following parameters:
int comedyReleaseTime[n]: release timesint comedyDuration[n]: durationsint dramaReleaseTime[m]: release timesint dramaDuration[m]: durations
Function
minimumTimeSpent(comedyReleaseTime: int[], comedyDuration: int[], dramaReleaseTime: int[], dramaDuration: int[]) β intExamples
Example 1
comedyReleaseTime = [1, 4]comedyDuration = [3, 2]dramaReleaseTime = [5, 2]dramaDuration = [2, 2]return = 6Duration and release time are aligned by index.
Two of the best ways to finish watching one movie from each category at the earliest time are as follows:
- Start watching comedy movie1 at time t = 1 and until t = 1 + 3 = 4. Then, watch the drama movie1 from time t = 4 to t = 4 + 2 = 6.
- Start watching a comedy movie2 at time t = 2 and until t = 2 + 2 = 4. Then, watch the drama movie1 from time t = 4 to t = 4 + 2 = 6.
The earliest finish time and also answer is 6.
Examples that are sub-optimal include:
- Start watching a comedy movie2 at time t = 4 and until t = 4 + 2 = 6. Then, watch the drama movie1 from time t = 6 to t = 6 + 2 = 8.
- Start watching a comedy movie1 at time t = 1 and until t = 1 + 3 = 4. Then, watch the drama movie1 from time t = 5 to t = 5 + 2 = 7.
Constraints
1 <= n, m <= 1051 <= comedyReleaseTime[i], comedyDuration[i], dramaReleaseTime[i], dramaDuration[i] <= 106More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW Β· Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA Β· Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW Β· Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW Β· Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW Β· Seen Jul 2026
- Merge IntervalsOA Β· Seen Jul 2026
- Sort Bug Report FrequenciesOA Β· Seen Jul 2026
- Drone Delivery RouteOA Β· Seen Jul 2026