Task Scheduler
Write the code, see it run, pass the checks.
The problem
- medium
- Code
- Pro
Write leastInterval(tasks, n): tasks is an array of 1 to 100,000 tasks, each an uppercase letter from "A" to "Z", and n, from 0 to 10,000, is the cooldown. Each time slot runs one task or stays idle, and two runs of the same letter need at least n slots between them. Tasks can run in any order. Return the fewest slots that run every task, idle ones included. Don't change tasks. For example, leastInterval(["A", "A", "A", "B", "B", "B"], 2) is 8: A, B, idle, A, B, idle, A, B. The checks include 100,000 tasks and long cooldowns, so stepping through the schedule one slot at a time is too slow.
Your code must pass
- Counts the slots in small examples
- Needs no idle slots when there's enough variety
- Handles a cooldown of 0
- Handles several letters tied for the most tasks
- Is fast enough for 100,000 tasks