Rank Top K Symbols by Traded Volume in a Stream
Last updated: November 29, 2026
Quick Overview
Process a stream of trades (symbol, quantity) and support a query at any time for the k symbols with the highest cumulative traded volume.
Akuna Capital
November 29, 20260
0
0 solved
Process a stream of trades (symbol, quantity) and support a query at any time for the k symbols with the highest cumulative traded volume.
Akuna Capital's trading dashboards and risk tools track where activity is concentrated across thousands of option underlyings. The interviewer probes whether you can keep a heap consistent when keys change, using lazy invalidation, and reason about memory growth from stale entries.
What the Interviewer Expects
- Keep a dict of current volume as the source of truth
- Use a heap of snapshots and skip stale ones on read
- Restore popped live entries after a query
- Bound heap growth with periodic rebuilds
- Compare with a sorted container or a full sort per query
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if you need top k over the last five minutes only?
- How would you handle millions of symbols with approximate counts?
- When is sorting the dict on each query actually the better choice?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
on_trade(symbol, qty) adds to that symbol's cumulative volume. top_k(k) returns up to k (symbol, volume) pairs in descending volume. Trades vastly outnumber queries....
High-Level Design
A max-heap cannot update a key in place, so every trade pushes a fresh snapshot (-volume, symbol) and older snapshots for that symbol become stale. On a query, pop entries, skip any whose volume doe...