Rank Words by Count
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
0 <= len(words) <= 1001 <= len(words[i]) <= 8- Lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.