Code Room
CodingMediumcod-g1161
Subject Database transactionLevel Mid–Senior~25 minCommon in Databases & SQL interviewsIndustries Software development

Question

Two concurrent transactions are described by their read sets and write sets over named data items (strings). Under optimistic concurrency control, the two transactions CONFLICT if any of these overlap: T1.write ∩ T2.write (write-write), T1.write ∩ T2.read (write-read), or T1.read ∩ T2.write (read-write). A read-read overlap is NOT a conflict. Given r1, w1, r2, w2 as lists of item names, return True if the transactions conflict, else False.

Implement
txn_conflict(r1: list[str], w1: list[str], r2: list[str], w2: list[str]) → bool
Examples
in[["x"],["y"],["y"],["z"]]outtrue
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.