Problem statement
Given a string, return its characters ordered by how often they appear, most frequent first, with every repeat kept.
Equal counts need a fixed tie-break, and this page breaks the tie by the letter itself so the answer is the same on every run.
Examples
Input"tree"
Output"eert"
e appears twice and r and t once each, so e comes first and the two singles follow in letter order.
Input"cccaaa"
Output"aaaccc"
a and c are both counted three times, and the letter breaks the tie.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing