Snapshot Array for Versioned Privacy Settings

Last updated: November 29, 2026

Quick Overview

Design an array of integer settings that supports set(index, value), snap() returning a snapshot id, and get(index, snap_id) returning the value at that snapshot. Snapshots must be cheap even when the array is large and few values change.

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

0

0

0 solved


Design an array of integer settings that supports set(index, value), snap() returning a snapshot id, and get(index, snap_id) returning the value at that snapshot. Snapshots must be cheap even when the array is large and few values change.

Meta keeps auditable history for privacy and audience settings, so reading a setting 'as of' an earlier version is a natural framing. The interviewer checks that you avoid copying the array on snap, and that you use per-index version lists with binary search.

What the Interviewer Expects
  • Reject copying the whole array per snapshot
  • Store per-index history as (snap_id, value) pairs
  • Overwrite in place when setting twice within the same snapshot
  • Use binary search to answer historical reads
  • Discuss memory proportional to changes, not snapshots
Key Topics to Cover
Binary search
Versioning
Copy-on-write
Data structure design
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 can read anymore?
  • What if reads mostly target the latest snapshot?
  • How would you persist this to disk for an audit log?
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 writes into the current (unsnapped) version.
  • snap() freezes the current version and returns its id (0, 1, 2, ...).
  • get(i, s) returns the value of index i as of snapshot s; unset va...
High-Level Design

For each index keep two parallel lists: the snapshot ids at which it changed and the values. Initialize with (0, 0). A set during snapshot k either overwrites the last entry if it already belong...


Submit Your Answer
Markdown supported