This question evaluates understanding of time-versioned data structures and efficient temporal lookup within associative mappings, focusing on storing and retrieving multiple values per key across timestamps.
Design a data structure that stores multiple values for the same key at different timestamps, and can retrieve the most recent value as of a given timestamp.
Implement a class TimeMap with the following operations:
set(key, value, timestamp)
value
for string
key
at integer
timestamp
.
get(key, timestamp) -> string
key
at the
largest timestamp t such that t <= timestamp
.
""
.
key
and
value
are strings.
timestamp
is a positive integer.
set
calls for the same key may be given in increasing timestamp order (state your assumption; if not guaranteed, handle it).
get
, where
m
is the number of stored timestamps for that key.