Code RoomOptimistic concurrency control
MediumPrep Room Coding #299

Optimistic concurrency control

CodingConcurrencyMid–Senior~25 min

Simulate optimistic concurrency control with version numbers. Each record starts at version 0. ops is a list of [txn_id, key, read_version] applied in order: the transaction read 'key' when it had version read_version and now wants to write. The write COMMITS only if the key's current version still equals read_version (no one wrote in between); on commit the key's version increments by 1. Otherwise the write ABORTS and the version is unchanged. Return a list of [txn_id, 'commit' | 'abort'] in op order.

Implement
occ_simulate(ops: list[list]) → list[list]
Examples
in[[[1,"x",0],[2,"x",0]]]out[[1,"commit"],[2,"abort"]]
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 25 min
InputExpectedGot
[[[1,"x",0],[2,"x",0]]][[1,"commit"],[2,"abort"]]not run yetsample