#2589
Minimum Time to Complete All Tasks
master · 1715 · lc hard +32 · verified · 39.7% accepted · 462 likes · top 19%
Description
A computer can execute unlimited tasks in parallel. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] means the i-th task needs exactly durationi seconds of runtime (not necessarily consecutive) within the window [starti, endi]. The computer switches on only when needed. Return the minimum total on-time needed to complete all tasks.
Example 1:
Input: tasks = [[2,3,1],[4,5,1],[1,5,2]]
Output: 2
Explanation:
- The first task can be run in the inclusive time range [2, 2].
- The second task can be run in the inclusive time range [5, 5].
- The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].
The computer will be on for a total of 2 seconds.
Example 2:
Input: tasks = [[1,3,2],[2,5,3],[5,6,2]]
Output: 4
Explanation:
- The first task can be run in the inclusive time range [2, 3].
- The second task can be run in the inclusive time ranges [2, 3] and [5, 5].
- The third task can be run in the two inclusive time range [5, 6].
The computer will be on for a total of 4 seconds.
Code
1
2
3