Quant Memo
Coding/●●●●●

Reorder a tape so no symbol repeats adjacently

Asked at Point72, Millennium

Given a multiset of symbols, produce any arrangement in which no two adjacent symbols are equal. If no such arrangement exists, return the empty string.

symbols = "AAB"
-> "ABA"           # no two neighbors match
symbols = "AAAB"
-> ""              # A occurs too often to separate

Return a valid rearrangement, or "" if impossible. Aim for O(nlogu)O(n \log u).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions