Time-Keyed Store
Simulate a key-value store with history. ["set", key, value, t] stores value for key at timestamp t (timestamps for a key strictly increase). ["get", key, t] returns the value with the largest timestamp for that key, or "" if there is none. Return the results of all get operations.
Requirements
- Binary search the timestamps of a key: per
get.
Examples
A guided view of the published example, not a trace of your code.
[[["set","foo","bar",1],["get","foo",1],["get","foo",3],["set","foo","bar2",4],["get","foo",4],["get","foo",5]]]["bar","bar","bar2","bar2"]Start with the input values shown in this example.
Input: operations = [["set","foo","bar",1],["get","foo",1],["get","foo",3],["set","foo","bar2",4],["get","foo",4],["get","foo",5]]
Output: ["bar","bar","bar2","bar2"]
Explanation: classic
Input: operations = [["get","x",10]]
Output: [""]
Explanation: missing key
Input: operations = [["set","a","v1",5],["get","a",4]]
Output: [""]
Explanation: too early
Hint 1
Keep, per key, parallel lists of timestamps and values.
Hint 2
bisect_right(times, t) - 1 gives the latest index at or before t.