Track Latest, Max and Min Price With Out-of-Order Corrections
Last updated: November 29, 2026
Quick Overview
A market data feed sends (timestamp, price) records, and a later record with an existing timestamp corrects the earlier price. Support update, current (price at the latest timestamp), maximum and minimum across all live records.
0
0
0 solved
A market data feed sends (timestamp, price) records, and a later record with an existing timestamp corrects the earlier price. Support update, current (price at the latest timestamp), maximum and minimum across all live records.
A Google onsite data-structure question in a Google Finance quote-feed frame. The interviewer wants lazy deletion: two heaps plus a hash map of truth, with stale heap tops discarded on read.
What the Interviewer Expects
- Uses a hash map from timestamp to current price
- Keeps max-heap and min-heap of (price, timestamp)
- Discards stale entries lazily on read
- Tracks the latest timestamp separately
- Explains amortized complexity
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 bound memory if corrections are frequent?
- Use a sorted container instead and compare
- Support max over a time range
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
update(ts, price): set or overwrite the price at ts.current(): price at the largest timestamp seen.maximum()andminimum(): over the current prices of all timestamps.- Reads are only ...
High-Level Design
The hash map price[ts] is the source of truth. For max and min, push (price, ts) into both a max-heap and a min-heap on every update, without removing old entries, because removing from the middle...