queries, each a single word, and an integer k. Return the k words that appear in the log most often.
Order the answer by frequency, highest first. Words with the same frequency go in alphabetical order.
Try to fit into O(n log k) time and O(n) extra space.queries=["tea", "cake", "tea", "jam", "cake", "tea", "bun"], k=3 → ['tea', 'cake', 'bun']
"tea" appears 3 times, "cake" twice, "bun" and "jam" once each. Of the last two, "bun" comes first alphabetically.
queries=["red", "blue", "red", "blue", "green"], k=2 → ['blue', 'red']
"red" and "blue" both appear twice, so alphabetical order decides between them.
queries[i] consists of lowercase English lettersqueriesqueries=["tea", "cake", "tea", "jam", "cake", "tea", "bun"], k=3
['tea', 'cake', 'bun']
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.