Loading
Loading
A bakery has one oven. Each letter in the order string is one tray of a product type, and every tray takes one time slot. After a tray of some type comes out, at least cooldown slots must pass before that same type goes in again, so flavours do not mix. Those slots can hold other trays or stay idle.
Given tasks (uppercase letters) and the integer cooldown, return the minimum number of time slots needed to bake every tray. Trays may be baked in any order.
tasks = "AAABBC", cooldown = 2Aslot 1A Bslot 2A B Cslot 3A B C Aslot 4: A is allowed againA B C A Bslot 5A B C A B _slot 6: idle, no type is allowedA B C A B _ Aslot 77Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
One schedule: A B C A B idle A — seven slots.
Example 2
Repeats are always at least one slot apart, so no idle slot is needed.