Time Based Key-Value Store
Design a key-value store that supports:
- set(key, value, timestamp) - Store the key-value pair at the given timestamp.
- get(key, timestamp) - Return the value with the largest timestamp <= given timestamp. Return "" if no such value.
You will receive a sequence of operations. Output the result of each get operation on a separate line.
Example
set,foo,bar,1;set,foo,bar2,4;get,foo,1;get,foo,3;get,foo,4;get,foo,5
bar bar bar2 bar2
- The input sequence is split into operations:
set(foo, bar, 1),set(foo, bar2, 4),get(foo, 1),get(foo, 3),get(foo, 4),get(foo, 5). - The
setoperations store key-value pairs at the given timestamps:(foo, bar, 1)and(foo, bar2, 4). - The
getoperations retrieve the value with the largest timestamp <= the given timestamp:get(foo, 1)returnsbarbecause .get(foo, 3)returnsbarbecause and there's no value at timestamp 2.get(foo, 4)returnsbar2because .get(foo, 5)returnsbar2because and there's no value at timestamp 5.
- The results of the
getoperations are output on separate lines, producing the given output.
Constraints
- 1 <= key.length, value.length <= 100
- 1 <= timestamp <= 10^7
- Timestamps for set are strictly increasing
- At most 2 * 10^5 operations