Task scheduler with cooldown
Mediumgreedycountingheap
Each entry in tasks is a letter naming a task that takes one time unit. Two runs of the same letter need at least n units between them (filled by other tasks or idle time). Return the least time to finish every task.
Example 1
Input: tasks = ["A","A","A","B","B","B"], n = 2 Output: 8
A B idle A B idle A B = 8.
Example 2
Input: tasks = ["A","C","A","B","D","B"], n = 1 Output: 6
Constraints
- 1 ≤ tasks.length ≤ 10⁴
- tasks[i] is an uppercase letter
- 0 ≤ n ≤ 100
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {string[]} tasks
* @param {int} n
* @return {int}
*/
function leastInterval(tasks, n) {
}