271. Task Scheduler
MediumHeap
You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of at least n intervals between two tasks with the same label. Return the minimum number of CPU intervals required to complete all tasks.
Examples
Input: ["A","A","A","B","B","B"] 2
Output: 8
Explanation: A B idle A B idle A B — 8 intervals with the required cooldown of 2 between same tasks.
Constraints
- 1 <= tasks.length <= 10^4
- tasks[i] is an uppercase English letter.
- 0 <= n <= 100
Loading...
Run checks all cases above. Submit evaluates all test cases.