Key-Value Map With Constant-Time Snapshots and Snapshot Deletion

Last updated: November 29, 2026

Quick Overview

Design a map supporting put, delete, get(key, snapshot_id=None), snapshot() that returns an id in O(1), and drop_snapshot(id) that reclaims versions no remaining snapshot or the live view can see.

Pure Storage
Coding & Algorithms
Software Engineer
Pure Storage
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Design a map supporting put, delete, get(key, snapshot_id=None), snapshot() that returns an id in O(1), and drop_snapshot(id) that reclaims versions no remaining snapshot or the live view can see.

Instant snapshots that cost nothing to take are a headline FlashArray feature, and SafeMode depends on snapshots that are cheap to keep and safe to reclaim. The interviewer looks for an epoch-based versioning scheme, binary search on version lists and a correct rule for which old versions can be garbage collected.

What the Interviewer Expects
  • Uses a global epoch so snapshot() is O(1) and copies nothing
  • Stores per-key version lists and finds the visible version by binary search
  • Represents deletes with tombstones so older snapshots still see the value
  • States the exact reclamation rule: keep a version only if some reader epoch falls in its lifetime
  • Collapses repeated writes within one epoch
  • Analyzes the cost of drop_snapshot and suggests making it incremental
Key Topics to Cover
MVCC
Binary search
Copy-on-write snapshots
Garbage collection
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 avoid scanning every key in drop_snapshot?
  • How would you support a writable clone created from a snapshot?
  • How does this relate to how a copy-on-write block map shares metadata pages?
  • How would you make snapshots immutable even to an administrator, as SafeMode requires?
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

snapshot() freezes the current view and returns an id; later writes must not change what that id sees. get(key, sid) returns the value as of that snapshot, or the live value with no sid. `drop_sna...

High-Level Design

Keep a counter epoch. A write is tagged with the current epoch. snapshot() returns the current epoch and increments it, so the snapshot sees exactly writes tagged at or below its id. Each key hold...


Submit Your Answer
Markdown supported

Related Questions