← 返回 uber 的题目列表Time Based Key-Value Store
类型:qbank
Design a time-based key-value data structure that supports storing multiple values for the same key at different timestamps, where a lookup returns the value tied to the largest timestamp at or before a queried time.
Time Based Key-Value Store
Design a time-based key-value data structure that supports storing multiple values for the same key at different timestamps, where a lookup returns the value tied to the largest timestamp at or before a queried time.
SWE
data-structure
hashmap
binary-search
in-memory-database
medium
Frequency
Single report
Last asked
2026-03-20
Stage
onsite-coding
Time Based Key-Value Store
Design a time-based key-value data structure that supports storing multiple values for the same key at different timestamps.
set(key, value, timestamp) stores the key-value pair, and get(key, timestamp) returns the value associated with the largest timestamp less than or equal to timestamp, or an empty string if none exists.
Examples
Example 1:
Input: ["TimeMap","set","get","get","set","get","get"] [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]
Output: [null,null,"bar","bar",null,"bar2","bar2"]
Constraints
1 <= key.length, value.length <= 100
1 <= timestamp <= 10^7
Timestamps for each key are strictly increasing across set calls.