← Questions

Top-k and bottom-k words in a list and in a stream

0
GoogleCodingLast asked Jan 2026
  1. Given a list of words, return the k most frequent and the k least frequent.
  2. Now the words arrive as a stream: keep both answers available at any moment.
  3. Discuss how to return only distinct words in the stream version.

Explain the data structures and the cost of each update and query.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding