You are given an array of tasks represented by capital letters and a non-negative cooldown n.
Each interval can complete one task or stay idle. Return the minimum number of intervals needed to finish all tasks.
Use a heap when the next smallest or largest candidate matters more than the full sorted order. Keep stale or no-longer-valid entries from affecting the answer.
Examples
Input: tasks = ["A","A","A","B","B","B"], n = 2 Output: 8
Input: tasks = ["A","C","A","B","D","B"], n = 1 Output: 6
Constraints
- 1 <= tasks.length <= 10,000
- tasks[i] is an uppercase English letter
- 0 <= n <= 100