Task Scheduler II
You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task.
You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task of the same type can be performed.
Each day, until all tasks have been completed, you must either:
- Complete the next task from
tasks, or - Take a break.
Return the minimum number of days needed to complete all tasks.
Example 1
Input
tasks = [1,2,1,2,3,1], space = 3Output
9One way to complete all tasks in 9 days follows the required spacing between same-type tasks, and it can be shown that the tasks cannot be completed in less than 9 days.
Example 2
Input
tasks = [5,8,8,5], space = 2Output
6One way to complete all tasks in 6 days follows the required spacing between same-type tasks, and it can be shown that the tasks cannot be completed in less than 6 days.
Constraints
- 1 <= tasks.length <= 10^5
- 1 <= tasks[i] <= 10^9
- 1 <= space <= tasks.length