Versioned Key-Value Store
NetflixOnsiteHard
Build an in-memory key-value store that keeps every version of every key. Keys and values are strings, and each write carries an integer timestamp. Writes may arrive out of timestamp order, and the same timestamp can be written more than once.
Each test drives one VersionedStore instance through a sequence of method calls and checks every return value.
Part 1: Put and get by time
Implement:
put(key, value, ts)storesvalueas the version ofkeyat timets. Ifkeyalready has a version at exactlyts, the new value replaces it. Returns nothing.get(key, ts)returns the value of the version ofkeywith the greatest timestamp that is at mostts, orNoneif there is no such version.
- Example 1
- init
[]- operations
[["put",["campaignA","v1",10]],["put",["campaignA","v2",20]],["get",["campaignA",15]],["get",["campaignA",20]],["get",["campaignA",5]],["get",["other",15]],["put",["k","a",5]],["put",["k","b",5]],["get",["k",5]],["get",["k",99]]]- Output
[null,null,"v1","v2",null,null,null,null,"b","b"]
Why: At time 15 the latest version at or before 15 is
v1(written at 10). At 20 it isv2, and at 5 there is none. The second write tokat time 5 replaces the first.
Constraints
1 <= len(operations) <= 2 * 10^4-10^9 <= ts <= 10^91 <= len(key) <= 101 <= len(value) <= 10keyandvalueare made of lowercase letters and digits
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.