Track the Best Bid Over a Rolling Time Window
Last updated: November 29, 2026
Quick Overview
Design a class that ingests timestamped bid prices in nondecreasing time order and answers, at any time t, the highest bid seen in the window (t - W, t], in amortized O(1) per operation.
SIG
November 29, 20260
0
0 solved
Design a class that ingests timestamped bid prices in nondecreasing time order and answers, at any time t, the highest bid seen in the window (t - W, t], in amortized O(1) per operation.
SIG traders watch short-horizon highs and lows of quotes, and this monotonic queue question appears in technical screens framed around a rolling statistic on market data. The interviewer checks that you reject a heap in favor of a monotonic deque and handle expiry at the exact boundary.
What the Interviewer Expects
- Clarify the window boundary: an update exactly W old has expired
- Keep a deque of (timestamp, price) with strictly decreasing prices
- Pop dominated entries from the back on insert
- Expire from the front on both insert and query
- Justify amortized O(1) by counting pushes and pops
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
- How would you support rolling minimum and maximum at the same time?
- What if updates can arrive slightly out of order, say by a few microseconds?
- How would you compute a rolling VWAP instead of a max?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add(ts, price) with nondecreasing ts; max_bid(now) returns the highest price among updates with ts > now - W, or None if the window is empty. Updates are snapshots of the bid, and we want th...
High-Level Design
A max-heap works with lazy deletion but costs O(log n) and keeps stale items around. Better: a deque where prices are strictly decreasing from front to back. When a new price arrives, any older entry ...