← 返回 amazon 的题目列表Design a Time-Based Key-Value Store
类型:online_judge
Design a timestamp-based key-value store class with two methods: __init__() and query(key: str, timestamp: int) -> str.
__init__() initializes the object without any parameters. This constructor must set initial values for each key.
query(key: str, timestamp: int) -> str returns the value associated with the provided key and timestamp. If there is no suitable value, return an empty string.
Requirements: Optimize time and space complexities as much as possible.
Constraints
The total length of the input strings will not exceed 10^5.
timestamp range is [1, 10^7].
Example
Input:
set('foo', 'bar', 1)
query('foo', 1)
query('foo', 3)
set('foo', 'bar2', 4)
query('foo', 4)
query('foo', 5)
Output:
bar
bar
bar2
bar2
Example
Input
set('foo', 'bar', 1)
query('foo', 1)