Problem. tasks is a list of task labels (letters A–Z). Each takes one time slot. Two runs of the same label must
be separated by at least n slots (other tasks or idle slots in between). Return the minimum number of slots to run
everything.
tasks = A A A B B B, n = 2 → 8 A B _ A B _ A B
tasks = A A A B B B, n = 0 → 6 no cooldown
tasks = A A A A A A B C D E F G, n = 2 → 16 A B C A D E A F G A _ _ A _ _ A
The greedy question at every slot: which ready task should run now? Answer: the one with the most copies left, because it's the one most likely to force idle slots later. A heap answers "the most remaining" in O(log) per step.
ML context. Schedulers in ML infrastructure face the same constraint: a tenant may submit at most one job per GPU every few minutes (rate limiting), a dataset shard shouldn't be read twice within a window, an evaluation suite can't rerun the same model within a cooldown. "Most remaining work first, among those allowed now" keeps throughput high and idle time low (Change C).