Version Warehouse Bin Quantities With Cheap Snapshots

Last updated: November 29, 2026

Quick Overview

Design an array of bin quantities with `set(index, value)`, `snap()` returning a snapshot id, and `get(index, snap_id)` returning the value at that index when that snapshot was taken. Snapshots must not copy the whole array.

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

0

0

0 solved


Design an array of bin quantities with `set(index, value)`, `snap()` returning a snapshot id, and `get(index, snap_id)` returning the value at that index when that snapshot was taken. Snapshots must not copy the whole array.

An onsite design-a-structure question in Amazon's style, framed around auditing inventory counts at the end of each cycle count without copying millions of bins. The interviewer wants per-index version history with binary search and a clear memory argument.

What the Interviewer Expects
  • Rejects full-copy snapshots as O(n) per snap
  • Stores per-index lists of (snap_id, value) changes
  • Overwrites the last entry when set is called twice in one snapshot
  • Uses binary search for get
  • States memory as O(number of sets plus n)
Key Topics to Cover
design a data structure
binary search
versioning
persistent data structures
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 garbage-collect snapshots nobody will read again?
  • How would you persist this to disk so it survives restarts?
  • How would you support get_range(l, r, snap_id) efficiently?
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

n bins start at 0. snap() freezes the current state and returns ids 0, 1, 2, and so on. get(i, s) returns bin i as of snapshot s. Up to 5⋅1045 \cdot 10^4 calls, so copying the array per snapsho...

High-Level Design

Store changes, not states. For each bin keep a list of (snap_id, value) pairs sorted by snap_id, where snap_id is the id of the snapshot that the next snap() call will return. Repeated sets wi...


Submit Your Answer
Markdown supported