621. Task Scheduler
Practice Task Scheduler for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
A CPU must run a list of tasks, each labelled with an uppercase letter. Every task takes one time unit. In each unit the CPU either runs one task or sits idle, and tasks can run in any order. Two runs of the same label must be at least n units apart (there must be at least n other units between them).
Return the minimum number of units needed to finish all tasks.
Example
tasks = ["A","A","A","B","B","B"], n = 2 -> 8 (A B idle A B idle A B)
Constraints
- 1 <= tasks.length <= 10^4
tasks[i]is an uppercase English letter- 0 <= n <= 100