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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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...