Versioned Settings Map With Snapshots for Feishu Docs
Last updated: November 29, 2026
Quick Overview
Design a key-value map with set, delete, snap and get(key, snap_id), where snap returns an id and get returns the value a key had when that snapshot was taken.
ByteDance
November 29, 20260
0
0 solved
Design a key-value map with set, delete, snap and get(key, snap_id), where snap returns an id and get returns the value a key had when that snapshot was taken.
Feishu (Lark) Docs keeps document and workspace settings with history so users can view or restore older versions. The interviewer wants a design that avoids copying the whole map on every snapshot, and expects you to justify the storage and lookup trade-off with binary search.
What the Interviewer Expects
- Avoid copying the full map at each snapshot
- Store per-key history ordered by snapshot id
- Use binary search for historical lookups
- Overwrite repeated writes within the same open snapshot
- Handle deletes and keys that did not exist yet
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 garbage-collect history older than the oldest snapshot anyone still references?
- How would you persist this so it survives restarts?
- What if snapshots must also be listable as full key sets efficiently?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
set(key, value) writes into the current open snapshot. snap() closes it and returns its id, starting at 0. get(key, snap_id) returns the value as of that snapshot, or None if unset or deleted....
High-Level Design
Keep, for each key, two parallel lists: snapshot ids where it changed and the value written. A write in the currently open snapshot either appends a new entry or overwrites the last entry if it was al...