Process deadlock detection
An operating system tracks a wait-for graph among n processes labeled 0..n-1. Each edge [a, b] means process a is blocked waiting for a resource currently held by process b. A deadlock exists if and only if there is a cycle in this directed graph. Return True if the system is deadlocked, otherwise False. The graph may have many edges and may be disconnected; self-loops [a, a] count as a deadlock.
Implement
has_deadlock(n: int, waits: list[list[int]]) → boolExamples
in
[3,[[0,1],[1,2],[2,0]]]outtrueWhat 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
solution.py
InputExpectedGot
[3,[[0,1],[1,2],[2,0]]]truenot run yetsample