Code RoomVersioned key-value store
HardPrep Room Coding #1536

Versioned key-value store

CodingStorage & CDNSenior~30 min

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.

0:00 of about 30 min
InputExpectedGot
[[["put","a",1],["snapshot"],["put","a",2],["get",0,"a"],["getlive","a"]]][1,2]not run yetsample