ASAPUtils Logo ASAPUtils
Week 4

Time Based Key-Value Store

Design TimeMap with O(1) append-only set and logarithmic get, using a hash map of sorted timestamp histories, rightmost-valid binary search, C++ and JavaScript implementations, and an interactive timestamp trace.

medium Hash Maps & Sets Binary Search set O(1), get O(log n) time · O(n) space Open on LeetCode ↗

The problem

Design a structure that stores values for string keys at increasing timestamps. A get operation returns the value with the greatest stored timestamp not exceeding the requested timestamp, or an empty string when none exists.

set("foo","bar",1); get("foo",1) -> "bar"; get("foo",3) -> "bar"

Related Problems