Time Based Key Value Store
Implement TimeMap. set(key,value,timestamp) saves a version; get(key,timestamp) returns the value with greatest saved time no later than timestamp, or an empty string if none exists.
Example 1
arg 1 = ["TimeMap","set","set","get","get","get"]
arg 2 = [[],["a","old",2],["a","new",5],["a",1],["a",4],["a",9]][null,null,null,"","old","new"]Explanation
Time 1 precedes all versions; time 4 selects old at 2, and time 9 selects new at 5.
Example 2
arg 1 = ["TimeMap","get","set","get"]
arg 2 = [[],["z",10],["z","ok",10],["z",10]][null,"",null,"ok"]Explanation
A missing key returns an empty string; an exact-time lookup after set returns ok.
Example 3
arg 1 = ["TimeMap","set","set","get","get"]
arg 2 = [[],["a","one",1],["b","two",2],["a",3],["b",1]][null,null,null,"one",""]Explanation
Updating key b does not change key a; querying a at time 3 selects its version from time 1.
Constraints
- At most 200000 operations
- set timestamps are strictly increasing globally and positive
- Keys and values are nonempty ASCII strings
Class contract
TimeMapArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
["TimeMap","set","set","get","get","get"][[],["a","old",2],["a","new",5],["a",1],["a",4],["a",9]]