Code RoomMVCC snapshot visibility
HardPrep Room Coding #336

MVCC snapshot visibility

CodingDatabases & SQLMid–Senior~28 min

Implement MVCC snapshot visibility for a single row. The row has multiple versions, each given as [version_id, created_ts, deleted_ts] where created_ts is when the version became live and deleted_ts is when it was superseded (use -1 for a version that is still live). A reader with snapshot timestamp `snap_ts` sees a version if created_ts <= snap_ts AND (deleted_ts == -1 OR deleted_ts > snap_ts). At most one version is visible at any snapshot. Return the version_id of the visible version, or -1 if none is visible. Versions are not pre-sorted.

Implement
mvcc_visible_version(versions: list[list], snap_ts: int) → int
Examples
in[[[1,0,10],[2,10,-1]],5]out1
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 28 min
InputExpectedGot
[[[1,0,10],[2,10,-1]],5]1not run yetsample