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

0
Remix
  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.

GoogleTechnical phone screenLast asked Jan 2026
No answer yet. Write the first one; the best answer gets endorsed.