← Questions
Streaming top-K frequent elements with O(1) updates
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
