Lock order deadlock cycle

Write codeHard35 minMicrosoft style

Your task

Given a trace of lock-acquisition attempts, determine whether the program can deadlock under the standard lock-order-cycle heuristic. The trace is a list of ops, each [thread, action, lock] where action is "acquire" or "release". A thread can hold multiple locks at once (nested locking). Build a lock-order graph: whenever a thread acquires lock Y while already holding lock X, add a directed edge X to Y (X is acquired-before Y by that thread). A potential deadlock exists iff this lock-order graph contains a cycle (two locks acquired in opposite orders by different paths). Return True if a cycle exists, else False. Assume the trace is well-formed (no releasing an unheld lock).

Examples

lock_order_deadlock(ops: list[list]) -> bool
Example 1
Inputlock_order_deadlock([[0, "acquire", "A"], [0, "acquire", "B"], [0, "release", "B"], [0, "release", "A"], [1, "acquire", "B"], [1, "acquire", "A"], [1, "release", "A"], [1, "release", "B"]])
OutputTrue