1/41
Learn

A store that remembers every change, the way the coding round asks

Time Based Key-Value Store is on OpenAI's and Netflix's LeetCode tag lists (2 sources), Snapshot Array is on OpenAI's (1 source), and two OpenAI candidates report a coding round in parts on a social graph with snapshots (2 reports). This lesson's practice problem is that shape, a configuration store, in three levels:

  1. ConfigStore with set(key, value, time) and get(key, time): the value of the latest change at or before a moment, in O(log n).
  2. Late changes that take their place in time, delete(key, time), and changes(key, start, end), a count from start up to end.
  3. snapshot() and get_snapshot(key, snap), without copying the store.
Call, after changes at 100 and 160Returns
get("timeout", 159.5)the value set at 100
get("timeout", 99)None: nothing at or before 99
get("timeout", 160)the value set at 160: a read at a change sees it
changes("timeout", 100, 160)1: the start counts, the end doesn't

The lesson builds it from the bottom: sorting, binary search by hand, the bisect module, versions, and binary search on the answer. 23 steps end with a small task in the editor.