Versioned Key-Value Store
Asked at Netflix
Reported by the problem's creator, not verified
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.
Examples
Example 1
Input: 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"]Explanation: 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.