Implement time-versioned KV store with restore
PerplexitySoftware Engineer · Online AssessmentLast updated
This question evaluates a candidate's ability to design and implement a time-versioned key–value store, assessing knowledge of temporal data structures, versioning semantics, time-travel and range queries, deletion semantics, and rollback/restoration.
Design and implement an in-memory key–value store where every operation is associated with a timestamp (monotonically increasing integer). The store must support time-travel queries and rollback.
Implement the following operations (you may choose function signatures, but the semantics must match):
set(key, value, ts): Setkeytovalueeffective at timets.get(key, ts): Return the value ofkeyat timets(the most recentsetat or beforetsthat hasn’t been deleted by timets). Returnnull/Noneif the key does not exist atts.delete(key, ts): Deletekeyeffective at timets.- Range query requirement: support querying a time interval for a key, e.g.
getRange(key, startTs, endTs), returning the value history within[startTs, endTs](for example, a list of segments or (timestamp, value) change points within the interval). restore(ts): Restore the entire store to exactly the state it had at timets(after all operations with timestamp<= ts), discarding the effects of any operations with timestamp> ts.
Discuss and/or implement data structures that make these operations efficient. Clarify any assumptions (e.g., whether multiple operations may share the same timestamp, and how ties are resolved).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.