Rotating Queue With Cooldown
Tasks wait in a queue, and tasks lists their kinds from front to back as uppercase letters. A processor runs one task per second, starting at second 0. After a task of some kind runs at second t, no task of that kind may run before second t + cooldown + 1.
Each second, if some waiting task may run, tasks that may not run are moved one at a time from the front to the back of the queue until the front task may run, and that task runs and leaves the queue. If no waiting task may run, the processor is idle and the queue stays as it is.
Return one character per second until the queue is empty: the kind that ran, or . for an idle second.
Example 1
The second A may not run before second 3. At second 1 it moves behind B, and second 2 is idle.
Example 2
At second 1 the front A must wait, so it moves to the back and B runs. At second 2 C is at the front and runs before A.
Constraints
0 <= len(tasks) <= 30tasksholds uppercase letters only0 <= cooldown <= 5
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Round Robin Completion TimesMedium
- Score of ParenthesesMedium
- Self Time per FunctionMedium
- Simplify PathMedium
- Two Teams in a CircleMedium
- Visible to the RightMedium
- Atoms in a Hydrate FormulaHard
- Best Pick With Small GapsHard