Algorithm · Meta · Hard
We need to process a very long, possibly unbounded, stream of tokens. Each token is either an integer or a string. The entire stream cannot be stored in memory; elements arrive one by one and must be processed online. Your task is to build a data structure that supports the following operation at any moment: topK(k) — return the k items with the largest occurrence counts among all tokens processed so far. Two scenarios must be handled: Exact case: Suppose the number of…
Checking your access…