Snapshot Array for OneDrive Version History Lookups

Last updated: November 29, 2026

Quick Overview

Implement an array of length n with set(index, value), snap() which returns a snapshot id, and get(index, snap_id) which returns the value at that index as of that snapshot, using memory proportional to the number of writes.

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

0

0

0 solved


Implement an array of length n with set(index, value), snap() which returns a snapshot id, and get(index, snap_id) which returns the value at that index as of that snapshot, using memory proportional to the number of writes.

Asked in Microsoft onsite loops for storage and collaboration teams, since OneDrive and SharePoint keep file version history without copying every file at every version. The interviewer checks that you avoid full copies per snapshot and use per-index history with binary search.

What the Interviewer Expects
  • Reject copying the array on each snap
  • Store per-index lists of (snap_id, value) changes
  • Overwrite in place when setting twice within the same snap
  • Answer get with a binary search for the last change at or before snap_id
  • State time and memory bounds
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 persist this so history survives a restart?
  • How would you expire snapshots older than 30 days?
  • How would this change if snapshots could branch, like Git?
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

All values start at 0. set writes into the current, not yet taken, snapshot. snap freezes the current state and returns ids 0, 1, 2 and so on. get(index, snap_id) returns the value that index ha...

High-Level Design

Store changes, not states. Each index keeps a list of (snap_id, value) pairs in increasing snap order, seeded with (-1, 0) so every lookup finds something. Multiple sets within the same pending sn...


Submit Your Answer
Markdown supported