Sort Characters By Frequency
Return a string with the same characters as s, ordered so that the characters that appear most often come first, and all copies of a character sit together. If two characters appear equally often, the one with the smaller character code comes first (so capital letters come before lowercase letters, and digits before letters).
Example 1
s "tree"
returns "eert"
e appears twice, then r and t once each: eert.
Example 2
s "Aabb"
returns "bbAa"
b twice, then A before a: bbAa.
Constraints
1 <= len(s) <= 50shas letters and digits
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Sort by Distance From ZeroEasy
- Sortable With One SwapEasy
- Sorting the SentenceEasy
- Find in a Mountain ListMedium
- Find in a Rotated ListMedium
- H-IndexMedium
- K Closest ValuesMedium
- Kth Smallest Pair SumMedium