Code Room
CodingMediumcod-g1129
Subject ConcurrencyLevel Mid–Senior~25 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

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.

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.