A single processor has a list of tasks to run. Each task is named by an uppercase letter, and tasks that share a letter are copies of the same job. Every task takes exactly one time slot, and in each slot the processor either runs one task or sits idle.
After running a task, the processor must let at least n slots pass before it runs another task with the same letter. Those slots can go to tasks with other letters, or stay idle. The tasks may run in any order.
Return the fewest time slots needed to finish every task, counting the idle ones.
The three X tasks need two slots between each pair of them. Y fills one of those four waiting slots, and the other three are idle.
Run them as P Q R P Q R S. Each second copy comes two slots after its first, so no slot is wasted and the answer is just the number of tasks.
With n = 0 there is no waiting at all, so the two K tasks can even run back to back.
Constraints
1 <= tasks.length <= 10⁴tasks[i] is a single uppercase English letter.0 <= n <= 100Think about the letter that appears most often. Its copies can never be closer than n + 1 slots apart, so they set a frame that every other task has to fit into.
7