Code Room
CodingHardcod-g973
Subject Storage structuresLevel Senior~30 minCommon in Storage & CDN interviewsIndustries Technology, Software development

Question

Implement a versioned key-value store with copy-on-write snapshots. Operations: ["put", key, value] writes to the live (current) version; ["snapshot"] freezes the current state and returns a snapshot id (0 for the first snapshot, 1 for the second, ...) — later writes must NOT affect already-taken snapshots; ["get", snapshot_id, key] reads key from the state as it was at that snapshot (-1 if the key was absent there); ["getlive", key] reads from the current live state (-1 if absent). Return a list with one entry per get and getlive operation, in order (snapshot operations are not added to the result list). Keys are strings, values are integers.

Implement
cow_store(ops: list[list]) → list[int]
Examples
in[[["put","a",1],["snapshot"],["put","a",2],["get",0,"a"],["getlive","a"]]]out[1,2]
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.