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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

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
Heap
Lazy Deletion
Hash Map
Streaming
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 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 Problems
Sample Answer
Requirements
  • update(ts, price): set or overwrite the price at ts.
  • current(): price at the largest timestamp seen.
  • maximum() and minimum(): 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...


Submit Your Answer
Markdown supported