~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Time-travel key-value store
Per-key sorted history + binary search on timestamp.
Notes
Recognise it when: "value as of time t", versioned data, history queries, snapshots.
times[key].append(t); values[key].append(v) # t increasing, so stays sorted
i = bisect.bisect_right(times[key], t) # count of entries <= t
return values[key][i - 1] if i else ""
- Deletes and expiries are history entries too (
Nonevalue, or anexpires_atfield). bisect(..., key=...)works on tuples in Python 3.10+.
Gotchas: bisect_right vs bisect_left at equal timestamps. Write out the boundary case before coding.
4 problems
Practical systems
Stateful stores Key-value stores, file systems, banks, with history.
Time-travel key-value store
- Basics: the value as of time t (bisect on history) basics py · c++ · java easy
- Time-Based Key-Value Store Citadel py · c++ · java easy
- Library display shelves over time py · c++ · java easy
- OA: Versioned store with real clocks and threads 4 levels OpenAI medium