Description
Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.
Examples
Input:
operations = ["set","get","get"], args = [["foo","bar",1],["foo",1],["foo",3]]Output:
["bar","bar"]Explanation:
At timestamp 1 and 3, 'foo' returns 'bar'.
Input:
operations = ["set","set","get","get","get"], args = [["user","alice",10],["user","bob",20],["user",15],["user",25],["user",5]]Output:
["alice","bob",""]Explanation:
Multiple values are stored for key 'user' at different timestamps. At timestamp 15, this gives 'alice' (latest value ≤ 15). At timestamp 25, this gives 'bob' (latest value ≤ 25). At timestamp 5, this gives empty string since no value exists at or before timestamp 5.
Input:
operations = ["set","set","set","get","get"], args = [["config","v1.0",100],["status","active",200],["config","v2.0",300],["config",250],["status",150]]Output:
["v1.0",""]Explanation:
Two different keys are used: 'config' and 'status'. At timestamp 250, 'config' returns 'v1.0' (the latest version at or before 250). At timestamp 150, 'status' returns empty string since 'status' was only set at timestamp 200, which is after the requested time 150.
Constraints
- •
1 ≤ key.length, value.length ≤ 100 - •
1 ≤ timestamp ≤ 10⁷