Optimal Task Scheduler
You are given a list of tasks with their durations and a number n that represents a cooldown interval. Each task may be repeated, and a cooldown period means that the same task cannot start again until n units of time have passed since its last execution. Implement a function to determine the minimum total duration needed to complete all the tasks. Tasks can be performed in any order, but the same task can only be started again after the cooldown period if it has been executed before.
[ [ 1, 2, 1, 1, 3 ], 2 ]
Explanation. A possible scheduling is: Task 1, Task 2, cooldown, Task 1, cooldown, Task 1, Task 3. This uses 7 units of time.
[ [ 1, 1, 2, 1 ], 2 ]
Explanation. A possible scheduling is: Task 1, cooldown, Task 1, cooldown, Task 2, Task 1. This schedule completes all tasks in 6 time units.
[ [ 1, 2, 3, 1, 2 ], 3 ]
Explanation. A possible scheduling is: Task 1, Task 2, Task 3, cooldown, Task 1, cooldown, Task 2. This schedule completes all tasks in 9 time units.
Follow-up: Can you think of an optimal strategy if tasks have different priorities or if some tasks could be skipped under certain conditions?
1. The number of tasks is at least 1 and at most 10000.\n2. Each task's duration is a positive integer.\n3. Cooldown interval `n` is a non-negative integer.
- Views
- 3