Versioned Key Value Store for Profile Field History
Last updated: November 29, 2026
Quick Overview
Implement a store with set(key, value, timestamp) and get(key, timestamp), where get returns the value set for key at the largest timestamp less than or equal to the given one, or an empty string if none exists.
0
0
0 solved
Implement a store with set(key, value, timestamp) and get(key, timestamp), where get returns the value set for key at the largest timestamp less than or equal to the given one, or an empty string if none exists.
LinkedIn keeps profile history for features like 'show what changed' and for compliance. The question checks per-key ordered storage, binary search for the floor timestamp, and handling out-of-order writes.
What the Interviewer Expects
- Stores a sorted list of timestamps and values per key
- Uses bisect_right minus one to find the floor
- Handles get before any set and timestamps before the first write
- Discusses out-of-order inserts with insort versus append
- Mentions memory and retention policies
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 support deleting a key as of a timestamp (tombstones)?
- How would you persist this efficiently on disk?
- What if you also need range queries for all changes in [t1, t2]?
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 is called with timestamps that are usually increasing per key but may arrive out of order from retries. get(key, t) returns the latest value at or before t. Same timestamp set twice keeps the ...
High-Level Design
Map each key to two parallel lists: times and values. On set, if t is at least the last timestamp, append (or overwrite when equal), which is O(1) for the common case. Otherwise insert at the bise...