Code Room
CodingMediumcod-g1050
Subject Storage snapshotLevel Mid–Senior~30 minCommon in Storage & CDN interviewsIndustries Software development, Technology

Question

Implement snapshot and restore over a key-value log. Process a list of operations on a string->int store: ["set", key, value] sets a key; ["del", key] deletes a key (no-op if absent); ["snapshot"] records a named checkpoint, where the name is its 0-based snapshot index (the first snapshot is 0, the second is 1, and so on); ["restore", id] reverts the entire store to the exact state it had at the moment snapshot `id` was taken (no-op if that snapshot id was never created). After all ops, return the final state as a list of [key, value] pairs sorted ascending by key. <= 10^4 ops.

Implement
snapshot_restore(ops: list[list]) → list[list]
Examples
in[[["set","a",1],["snapshot"],["set","a",9],["restore",0]]]out[["a",1]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.