Quant Memo
Coding/●●●●●

Sort characters by fill frequency

Given a string of fill codes, rearrange its characters so the most frequent character comes first (repeated as many times as it occurs), then the next most frequent, and so on. Break ties alphabetically.

fills = "tree"
-> "eert"          # e appears twice, then r, t alphabetically

Return the frequency-sorted string. Aim for O(n+ulogu)O(n + u \log u).

Your answer

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

More Coding questions