Time-Versioned Menu Price Store With Historical Lookups

Last updated: November 29, 2026

Quick Overview

Design a store where merchants set item prices over time with set_price(item, cents, ts), and support price_at(item, ts) returning the price that was in effect at any past timestamp.

DoorDash
Coding & Algorithms
Software Engineer
DoorDash
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Design a store where merchants set item prices over time with set_price(item, cents, ts), and support price_at(item, ts) returning the price that was in effect at any past timestamp.

When a customer disputes a charge or support reprices a refund, DoorDash needs the menu price at the moment the order was placed, not today's price. This data structure question checks per-key sorted histories, binary search for the floor timestamp, and explicit rules for same-timestamp writes and out-of-order writes.

What the Interviewer Expects
  • Store a per-item list of timestamps and prices
  • Use bisect_right minus one to find the latest change at or before ts
  • Define behavior for queries before the first price
  • Decide how equal timestamps and backwards timestamps are handled
  • Discuss persistence and how this maps to a database index
Key Topics to Cover
design a data structure
binary search
versioning
hash maps
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 support out-of-order writes from offline merchant tablets?
  • How would you compact history older than two years?
  • How would you model this in SQL so the lookup is a single indexed query?
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
  • set_price(item, cents, ts): timestamps are non-decreasing per item; an equal timestamp overwrites (a correction); a lower one is an error.
  • price_at(item, ts): price from the latest set_price...
High-Level Design

Keep two dictionaries of parallel lists, times[item] and prices[item]. Appends keep times sorted, so a query is bisect_right(times, ts) - 1: the index of the last change at or before ts. An ...


Submit Your Answer
Markdown supported