Write an algorithm to find the top K most frequent words in a (pre-parsed) document.
Asked in the onsite 3 stage. Reported follow-ups: What if the document is a stream? What if k is 0?
Implement top_k_frequent_words(words, k), where words is a list of strings and k is a nonnegative integer. Return up to k words ordered by decreasing frequency. Break equal-frequency ties in lexicographical order. Return an empty list when k is 0 or words is empty.
def top_k_frequent_words(words, k):