Time Based Key-Value Store

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Time Based Key-Value Store

Approach

Store entries per key in timestamp-sorted order (set calls are already chronological). On get, binary search the entries for the largest timestamp that does not exceed the query timestamp.

Complexity Analysis

Time
O(log n) per get
Space
O(n)

Pattern

Binary Search (Boundary Finding)

Why It Works

Values for each key are stored in timestamp order. Binary search finds the rightmost entry with timestamp <= the query timestamp.

Updated Feb 2026