Count the places without building the schedule
A close cousin allows idle places. Tasks run one per place, a task can't run again within k places, and an idle place is allowed. How few places can every task fit in?
The most common task sets the frame. If A runs m times, its runs need k places between each pair, so the frame is (m - 1) * (k + 1) places, plus one for the last A. With A 3 times and k = 2:
| Place | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Task | A | A | A |
Every other task with the same count m adds one place at the end, after the last A. Everything else fills the gaps. So the frame is (m - 1) * (k + 1) + c, with c the number of tasks tied at m.
If there are more tasks than the frame has room for, nothing ever idles, and the answer is the total number of tasks. So the answer is the larger of the two.
The formula is easy to get wrong in two ways: forgetting c, and forgetting the total. A simulation in the tests checks it against a step-by-step schedule on 300 random cases.
The editor holds slots. Write slots(counts, k) with the formula.