Medium data structure and algorithm practice puzzle.
Given a write-ahead log as entries of [transaction, kind] where kind 0 is a write and 1 is a commit, return how many writes should be applied during recovery. A write only counts if its transaction reached a commit record, which is what makes a crash mid-transaction safe: the incomplete work is simply never replayed. Two passes, because you cannot know whether the first write survives until you have seen the end of the log. This site's database runs in exactly this 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.
Browse all 536 puzzles