Detect resource deadlock

Write codeMedium35 minOracle style

Your task

Detect deadlock from a resource wait-for graph. You are given a list of [holder, waiter] edges meaning the waiter thread is blocked waiting on a resource currently held by the holder thread. A deadlock exists iff this directed graph contains a cycle. Return True if any cycle exists, otherwise False. Thread identifiers are arbitrary hashable values (ints).

Examples

has_deadlock(edges: list[list[int]]) -> bool
Example 1
Inputhas_deadlock([[1, 2], [2, 3], [3, 1]])
OutputTrue