The input is an array of strings words and an integer k. Return the k most frequent strings, sorted by frequency from highest to lowest. If words have the same frequency, the one that comes first in alphabetical order should appear first. Amazon asks top-K problems frequently, testing your heap and sorting strategy choices.
For example, given ["the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"] and k = 4, the answer is ["the", "is", "sunny", "day"]. "the" appears times, "is" times, "sunny" times, and "day" time.
The follow-up asks for a solution better than time. What data structure lets you maintain only the top k without fully sorting?