Design a time-based key-value store that can store multiple values for the same key at different timestamps, and retrieve the value associated with a key at (or just before) a given timestamp.
set("foo","bar",1); get("foo",1)"bar"get("foo",3); set("foo","bar2",4); get("foo",4)"bar", "bar2"Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Repeatedly halve the search space by comparing the middle element to a target, turning an O(n) scan into O(log n). It works on more than sorted arrays — any "answer space" that's monotonic (true…true…false…false) can be binary searched.
Read the full Binary Search guide →
Original problem on LeetCode ↗