Question
A set of threads is in a livelock if they keep yielding to each other forever without progress. Model each thread's behaviour as a function over a global 'state' integer: transitions is a list of [thread_id, from_state, to_state]. Starting from a given initial state, a deterministic round-robin runtime repeatedly: looks at the current state, finds the FIRST transition (in list order) whose from_state matches, applies it (state := to_state), and continues. Detect whether the system livelocks (enters an infinite loop of state changes) or eventually halts (reaches a state with no applicable transition). Return True if it livelocks, False if it halts.
detect_livelock(transitions: list[list[int]], initial_state: int) → bool[[[0,1,2],[1,2,1]],1]outtrueState 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.