You need to design an in-memory component that tracks how often each key appears in a stream of events.
The component must support these operations:
record(key)
: increment the count for
key
by 1 (insert
key
if not present).
topK(k)
: return the
k
keys with the highest counts so far (order among them does not matter).
Assume:
N
distinct keys.
Describe how you would implement this component under two different workload patterns:
topK(k)
calls than
record(key)
calls.
record(key)
calls than
topK(k)
calls.
For each case, specify:
record
and
topK
.
Login required