Code Room
CodingHardcod-g228
Subject Concurrency simulationLevel Senior–Staff~35 minCommon in Concurrency · Algorithms & data structures interviewsIndustries Software development

Question

Detect whether a set of transactions is deadlocked given a wait-for graph. Input is a list of (a, b) edges meaning transaction a is waiting for a resource held by transaction b. A deadlock exists if and only if this directed graph contains a cycle. Return True if any cycle exists, else False. Node labels are arbitrary hashable values; an edge may appear more than once; self-loops (a waits for itself) count as a cycle. The edge list may be empty.

Implement
has_deadlock(edges: list[tuple]) → bool
Examples
in[[["t1","t2"],["t2","t3"],["t3","t1"]]]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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.