Return a string with the characters of s grouped together, ordered by how often they appear: the most frequent character first, each character repeated as many times as it occurs. If two characters appear equally often, the smaller character (in alphabetical order) comes first.
Example 1
Input:
sort_by_frequency('tree')
Output:
'eert'
e appears twice, r and t once: eert.
Example 2
Input:
sort_by_frequency('cccaaa')
Output:
'aaaccc'
a and c tie, so a comes first.
0 <= len(s) <= 3 * 10**5s contains letters and digits.No results yet
Run your code to check it against the examples, or submit to run every test.