dsa · medium
Time-Based Key-Value Store
TimeMap: set(key, value, timestamp) timestamps strictly increase per key. get(key, timestamp) → value at the largest ts <= timestamp, or "".
Methods
TimeMap()construct the structureset(key, value, timestamp)setkeytovalueattimestampget(key, timestamp)look up; missing is-1unless the statement says otherwise
Fill in the TimeMap class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.
Example
`` TimeMap() → null set("foo", "bar", 1) → null get("foo", 1) → "bar" get("foo", 3) → "bar" set("foo", "bar2", 4) → null get("foo", 4) → "bar2" get("foo", 5) → "bar2" ``
Constraints
Calls <= 1000
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]] Expected: [null,null,"bar","bar",null,"bar2","bar2"]