Task Scheduler
Implement taskScheduler
You are given a list of tasks, each identified by a single uppercase letter, and a non-negative integer n — the number of full time units that must pass after running a task before another task of that exact same type can run again.
Each time unit, the CPU can either execute one task or sit idle. Find the minimum number of time units needed to finish every task in the list while respecting the cooldown between two tasks of the same type.
Example 1:
Input: tasks = ["X","X","X","Y","Y","Z"], n = 2
Output: 7
Example 2:
Input: tasks = ["M"], n = 3
Output: 1
Example 3:
Input: tasks = ["P","Q","P","Q"], n = 1
Output: 4
+ 6 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ tasks.length ≤ 50 - ●
tasks[i] is a single uppercase English letter ('A' to 'Z') - ●
0 ≤ n ≤ 20
tasks =
["X", "X", "X", "Y", "Y", "Z"]
n =
2