Track Latest, Highest and Lowest Ad Price With Late Corrections
Last updated: November 29, 2026
Quick Overview
Ad price updates arrive as (timestamp, price), and a later update for an existing timestamp corrects it. Support update, current (price at the latest timestamp), maximum, and minimum over all current records.
Meta
November 29, 20260
0
0 solved
Ad price updates arrive as (timestamp, price), and a later update for an existing timestamp corrects it. Support update, current (price at the latest timestamp), maximum, and minimum over all current records.
Framed around Meta's ads auction where price feeds get corrected after the fact, this technical-screen question tests lazy deletion in heaps. The interviewer wants to see stale entries skipped on read instead of searched and removed on write.
What the Interviewer Expects
- Store the authoritative price per timestamp in a hash map
- Track the latest timestamp separately
- Push every update into max and min heaps
- Lazily discard heap tops that disagree with the map
- Explain 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
- Could a sorted container replace the two heaps?
- How much memory do stale entries cost, and when would you rebuild?
- Support deleting a timestamp entirely.
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 correct the price for ts.current(): price at the largest timestamp seen.maximum(),minimum(): over current prices of all timestamps.- At least one update hap...
High-Level Design
A heap cannot delete an arbitrary element cheaply, so do not try. Instead:
price_atmap holds the truth for each timestamp.- Every update pushes
(price, ts)into a min-heap and(-price, ts)i...