Rank the Top K Assets by Trailing One-Hour Volume

Last updated: November 29, 2026

Quick Overview

Consume a stream of trades with timestamp, asset and USD notional, and answer at any moment which k assets had the most volume over the trailing hour.

Coinbase
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Consume a stream of trades with timestamp, asset and USD notional, and answer at any moment which k assets had the most volume over the trailing hour.

The Coinbase app and website surface top movers and most traded assets, refreshed continuously from the trade stream. The interviewer checks that you combine window expiry with aggregation and choose an efficient top-k extraction rather than sorting every asset each time.

What the Interviewer Expects
  • Maintain per-asset running totals and a time-ordered deque for expiry
  • Expire before both writes and reads
  • Use heapq.nlargest for O(A log k) queries
  • Clarify window boundaries and tie-breaking
  • Discuss when to switch to bucketed counters for memory
Key Topics to Cover
heaps
top-k
sliding window
hashing
streams
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you serve this to millions of app users without recomputing per request?
  • How would you handle trades arriving a few seconds late?
  • What if you must report the top k by percentage price change instead?
  • How would you bound memory with one-minute buckets?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

add_trade(ts, asset, usd) in non-decreasing time and top_k(now, k) returning (asset, volume) pairs for the window (now - 3600, now]. Ties broken deterministically....

High-Level Design

A deque of trades in arrival order supports eviction from the left, and a dict holds each asset's volume in the window. Expiry pops trades older than the window and subtracts them. A query expires fir...


Submit Your Answer
Markdown supported

Related Questions