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

0

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
lazy deletion
two heaps
hash map
amortized analysis
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
  • 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 Problems
Sample 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_at map holds the truth for each timestamp.
  • Every update pushes (price, ts) into a min-heap and (-price, ts) i...

Submit Your Answer
Markdown supported