Compute Rolling Highs and Lows for Live Price Candles
Last updated: November 29, 2026
Quick Overview
Given a stream of price ticks with timestamps, output for every tick the highest and lowest price over the trailing time window, in amortized constant time per tick.
Coinbase
November 29, 20260
0
0 solved
Given a stream of price ticks with timestamps, output for every tick the highest and lowest price over the trailing time window, in amortized constant time per tick.
The Coinbase price charts and Advanced Trade candles show highs and lows over sliding windows, and market data services compute them for every tick. The interviewer is checking whether you know the monotonic deque technique and can adapt it from a fixed count window to a time window.
What the Interviewer Expects
- Explain why a heap needs lazy deletion and a deque does not
- Maintain one decreasing deque for max and one increasing deque for min
- Pop the back while the new price dominates
- Evict the front by timestamp, not by count
- Prove amortized O(1) per tick
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 produce fixed one-minute OHLC candles instead of a rolling window?
- How would you handle late ticks that arrive out of order?
- How would you compute rolling VWAP alongside the high and low?
- How would you scale this to every trading pair on one host?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Ticks (ts, price) with non-decreasing timestamps. For each tick, report max and min price among ticks with timestamp in (ts - window, ts]....
High-Level Design
Keep indices in a deque whose prices are strictly decreasing for the max. A new price removes every smaller or equal price from the back, since those can never be the max while the new tick is in the ...