23/30
Part 6 of 7 · The worked exampleLearn and do

Test the edges, then give the cost

The edges for a cooldown problem:

  • k = 0: no rule at all, so repeats are fine.
  • One letter: possible only if it appears once, or k is 0.
  • A letter that fills more than its share: impossible, and you return an empty string.
  • Ties in the counts: the tie-break decides the output, so say it.
  • Empty input: an empty string, and not an error.

A checker is worth more than any one of those tests. Write far_enough(s, k) once and run it on every output, including hundreds of random inputs. It also checks the billboard: for a run with no updates, two showings of a title must stand more than k calls apart, except where the fallback had no other choice.

The cost of spread: each place does one pop and at most one push on a heap of a distinct letters, so it's O(n log a) for n letters in all. slots is O(a). The billboard's cooldown is O(k) extra per get at most.

The editor holds far_enough. Write far_enough(s, k) so it returns True when every two equal letters in s stand more than k places apart.