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. Return the result as a string.
Examples
Input:
operations = ["set","get","get"], args = [["foo","bar",1],["foo",1],["foo",3]]Output:
["bar","bar"]Explanation:
At timestamps 1 and 3, "foo" returns "bar", so the result is ["bar","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:
At timestamp 15 the latest value is "alice", at 25 it is "bob", and at 5 there is no earlier value, so the result is ["alice","bob",""].
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⁷