~/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.

Stateful stores

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 (None value, or an expires_at field).
  • 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

esc