dsa · medium

Time-Based Key-Value Store

GreyOrangeHash MapBinary SearchDesign

TimeMap: set(key, value, timestamp) timestamps strictly increase per key. get(key, timestamp) → value at the largest ts <= timestamp, or "".

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"]

Open in the Dojo editor