Task Scheduler
MediumHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.A CPU has to run a list of tasks, each labelled with a capital letter. Each task takes one time unit. After running a task, the same label cannot run again for n units (a cooldown). In any unit the CPU either runs one task or sits idle. Tasks can run in any order.
Return the fewest time units needed to finish everything.
tasks = ["A","A","A","B","B","B"], n = 2 → 8 (A B idle A B idle A B)
tasks = ["A","A","A","B","B","B"], n = 0 → 6 (no cooldown)
tasks = ["A","C","A","B","D","B"], n = 1 → 6 (A B A B C D)Constraints
1 <= tasks.length <= 10^4tasks[i]is an uppercase English letter.0 <= n <= 100