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
Coding & Algorithms
Software Engineer
SIG
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
monotonic deque
sliding window
amortized analysis
streaming data
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 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported