981. Time Based Key-Value Store
Practice Time Based Key-Value Store for free on NudgeCode: Medium, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a key-value store that keeps every version of a value, each tagged with a timestamp.
set(key, value, timestamp)storesvalueforkeyat timetimestamp.get(key, timestamp)returns the value set forkeyat the largest timestamp that is<= timestamp, or""if there is none.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor and for calls that return nothing).
Example
["TimeMap","set","get","get","set","get","get"]
[[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]
-> [null,null,"bar","bar",null,"bar2","bar2"]
Constraints
- Timestamps passed to
setare strictly increasing across all calls - 1 <= key.length, value.length <= 100
- 1 <= timestamp <= 10^7
- Up to 2 * 10^5 calls in total