Shortest Schedule With Cooldown
tasks is a string of uppercase letters; each letter is one unit of work of that kind. A schedule is a sequence of slots, each holding one task or left idle, and two tasks of the same kind must have at least gap slots between them (slots holding other tasks or idle). The tasks can be done in any order.
Return the length of the shortest schedule that completes every task. The shortest length is unique, so no tie rule is needed. Return 0 for the empty string.
Example 1
A B _ A B has two slots between the As and between the Bs: 5 slots, and no shorter schedule separates both pairs.
Example 2
A B _ A B _ A B works: the As and Bs alternate with one idle slot after each pair, 8 slots.
Constraints
0 <= len(tasks) <= 60taskshas uppercase letters only0 <= gap <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.