You are given a list of words and a number k.
Your task is to identify the k words that appear the most often in the list.
If two words have the same frequency, the word which is alphabetically smaller should come first.
The final result must be sorted first by frequency (descending) and then by lexicographical order (ascending).
Return the final list of k words.
Input: words = ["apple","banana","apple","orange","banana","apple"], k = 2
Output: ["apple","banana"]
Explanation:
"apple" appears 3 times, "banana" appears 2 times, and "orange" appears once.
Input: words = ["cat","dog","cat","bird","dog","dog"], k = 2
Output: ["dog","cat"]
Explanation:
"Dog" (3 times) > "Cat" (2 times).
Accepted:
Submission: