← Questions

Streaming top-K frequent elements with O(1) updates

0
NvidiaCodingLast asked Sep 2026

Elements arrive one at a time from an unbounded stream. Design a structure that can report, at any moment, the K elements seen most often so far. Clarify what K is and whether it changes, then avoid a heap: keep frequency buckets in a doubly linked list with a map from element to its bucket, so each update costs O(1) and reading the top K costs O(K). State the cost of every operation.

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