FunctionRacerProblemsRace

Rank Words by Count

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

Return the distinct words of words ordered by how many times each one appears, most frequent first. Words that appear the same number of times are ordered alphabetically. Each word appears once in the answer.

All words are lowercase. An empty list gives [].

Example 1

words ["pear","fig","pear","kiwi","fig","pear"]
returns ["pear","fig","kiwi"]

pear appears 3 times, fig 2 times, kiwi once.

Example 2

words ["b","a","c","a","b"]
returns ["a","b","c"]

a and b appear twice each and a comes first alphabetically; c appears once.

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