Code RoomTransaction conflict detection
MediumPrep Room Coding #335

Transaction conflict detection

CodingDatabases & SQLMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[["x"],["y"],["y"],["z"]]truenot run yetsample