You get a list of strings words and an integer k. Count how many times each different word appears, and return the k words with the highest counts.
The answer's order is fixed, and it is judged exactly:
"car" before "card".red appears three times, blue twice and green once, so the two most common words are red and then blue.
fig and pear both appear twice, and fig comes first alphabetically. apple and kiwi tie for the third place with one each, and apple wins the tie.
car and card tie with two each. car is a prefix of card, so it comes first.
Constraints
1 <= words.length <= 5001 <= words[i].length <= 10words[i] is made of lower-case English letters only.1 <= k <= the number of different words in wordsFirst count how often each word appears with a hash map. What's left is ordering the different words by two keys.