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
Examples
01 Β· Example 1
comedyReleaseTime = [1, 4] comedyDuration = [3, 2] dramaReleaseTime = [5, 2] dramaDuration = [2, 2] return = 6
Duration 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
- Count Promotional PeriodsOA Β· Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA Β· Seen Jun 2026
- Find Minimum CostOA Β· Seen Jun 2026
- Get Smallest Base SegmentOA Β· Seen Jun 2026
- Select Least Resource TasksOA Β· Seen Jun 2026
- Product Category Group SizesPHONE SCREEN Β· Seen May 2026
- Count Connected ComponentsPHONE SCREEN Β· Seen May 2026
public int minimumTimeSpent(int[] comedyReleaseTime, int[] comedyDuration,
int[] dramaReleaseTime, int[] dramaDuration) {
// write your code here
}
comedyReleaseTime[1, 4]
comedyDuration[3, 2]
dramaReleaseTime[5, 2]
dramaDuration[2, 2]
expected6
sign in to submit