Transaction conflict detection

Write codeMedium25 minOracle and Snowflake style

Your task

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.

Examples

txn_conflict(r1: list[str], w1: list[str], r2: list[str], w2: list[str]) -> bool
Example 1
Inputtxn_conflict(["x"], ["y"], ["y"], ["z"])
OutputTrue