InterviewDryRun
Medium

Top K Frequent Words

Read k on the first line and a list of words on the second. Print the k most frequent words, most frequent first; ties broken alphabetically.

Sample input
2
the day is sunny the the the sunny is is
Expected output
the
is

Stuck? Read how to approach Top K Frequent Words: what the interviewer looks for, an answer outline and common mistakes.

OUTPUT

Press Run tests to check your code, or Run to try the input on the left. Everything runs in your browser.

Passing the tests is half the round

In an interview you also explain the approach, state the complexity and handle a follow-up while someone listens. Max asks this exact question, pushes on the weak spots and scores you at the end.

Practice with Max

Free: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.

More practice problems