Medium data structure and algorithm practice puzzle.
Given a write-ahead log as [transaction, kind] entries, where kind 0 is a write and 1 is a commit, return how many writes should be replayed after a crash. A write only counts if its transaction committed somewhere in the log. That takes two passes: first find every committed transaction, then count their writes. This site's database runs in this exact mode.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Every line of the solution comes with a note explaining why it is there, and a step by step replay shows the code running. At level 3, where you type it yourself, you can ask for an AI mock interview on this problem that ends with a hiring manager's scorecard.
Browse all 546 puzzles