Problem
Design a class TimeMap that stores several values for the same key at different times, and can look up a key as of a given moment.
- set(key, value, timestamp) stores value for key at time timestamp.
- get(key, timestamp) returns the value stored for key with the largest timestamp that is `<=` `timestamp`. If there is none, return "".
Example 1
tm = TimeMap()
Example 2
tm.set("foo", "bar", 1)Example 3
- Input
- tm.get("foo", 1)
- Output
- "bar"
Example 4
- Input
- tm.get("foo", 3)
- Output
- "bar"
- Why
- latest value at or before 3
Example 5
tm.set("foo", "bar2", 4)Example 6
- Input
- tm.get("foo", 4)
- Output
- "bar2"
Example 7
- Input
- tm.get("foo", 5)
- Output
- "bar2"
Example 8
- Input
- tm.get("foo", 0)
- Output
- ""
- Why
- nothing stored that early
Constraints
1 <= key.length, value.length <= 1001 <= timestamp <= 10^7The timestamps passed to set are strictly increasing.At most 2 * 10^5 calls to set and get in total.