Standard Bar Strings · Medium O(n log n) · O(n)
A network operations center triages a feed where every event is a single-character code, and by the end of a shift some codes have fired far more often than others. The digest printer re-emits the whole feed rearranged so the noisiest codes lead, repeating each code once per occurrence. Codes tied at the same frequency may land in any order — only the ranking is contractual.
Input: A string s of characters.
Output: A rearrangement of s in which every character's block is no shorter than the block of any character that follows it; ties may be ordered arbitrarily.
1 <= s.length <= 5 * 10^4s consists of uppercase and lowercase English letters (case matters: 'A' and 'a' are different characters)Input: {"s":"tree"}
Output: "eert"
e occurs twice so both e's lead; the once-occurring letters follow in either order.
Input: {"s":"cccaaa"}
Output: "cccaaa"
Two codes tie at three occurrences, so either block may lead — the stored answer keeps the c block first.