Write a function top_words that takes a string of text and a number n, and returns the n most frequent words as a list of pairs: the word and how many times it occurred. Case doesn't matter, punctuation is discarded, and words with equal frequency are ordered alphabetically.
~15 min by voice
How to approach it
This checks whether you can carefully split text into words, count frequencies and sort by a compound key with a tie-breaker. Just as important is whether you clarify the problem before coding and think about edge cases.
The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.