FunctionRacerProblemsRace

Sort Characters By Frequency

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems