Heap / Priority Queue
LC #621Medium
Task Scheduler
Heap / Priority Queue
MetaAmazonGoogleBloombergProblem
Given tasks and a cooldown n, find the minimum time to execute all tasks (same task must wait n intervals between executions).
arrayheapgreedy
Constraints
- ›1 ≤ tasks.length ≤ 10⁴
- ›tasks[i] is uppercase English letter
- ›0 ≤ n ≤ 100
Example
Input
tasks = ["A","A","A","B","B","B"], n = 2Output
8Why
A→B→idle→A→B→idle→A→B. 8 intervals with cooldown n=2 between same tasks.