Key-value store with history
Write a class HistoryMap that keeps every version of each key.
set(key, value, time)storesvalueas the version ofkeyattime.get(key, time)returns the value of the newest version ofkeystored at a time<= time, orNoneifkeyhad no version yet at that time.
The times given to set are positive integers that strictly increase from one call to the next; a get may ask about any time >= 0. Keys and values are strings; a value may be empty. set must take O(1) amortized time and get O(log v), where v is the number of versions of that key.
The tests call the provided run_history(ops): it applies each operation in order and returns the list of results (None for set, shown as null).
Besides the tests, one large input (10,000 versions, 10,000 lookups) with a ~500 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_history([["set","color","red",1],["get","color",1],["get","color",3],["set","color","blue",4],["get","color",4],["get","color",5],["get","color",3]])→[null,"red","red",null,"blue","blue","red"]run_history([["set","v","1.0",5],["set","v","1.1",8],["set","v","2.0",20],["get","v",7],["get","v",8],["get","v",19],["get","v",100]])→[null,null,null,"1.0","1.1","1.1","2.0"]