Write-ahead log recovery

Write codeMedium25 minOracle and Microsoft style

Your task

Recover the final key-value state by replaying a write-ahead log. The log is a list of records: ["set", key, value] sets a key, ["del", key] deletes a key (no-op if absent), and ["commit"] / ["abort"] close the current transaction. Records appearing AFTER the last ["commit"] or ["abort"] (i.e. an uncommitted trailing transaction) must be discarded during recovery, a crash left them un-durable. Apply committed records in order; aborted records are rolled back (never applied). Return the final state as a list of [key, value] pairs sorted by key. Keys/values are strings; <= 10^5 records.

Examples

wal_replay(log: list[list]) -> list[list]
Example 1
Inputwal_replay([["set", "a", "1"], ["commit"], ["set", "b", "2"]])
Output[["a", "1"]]