Verify daisy chain rig
A lighting crew cables a stage rig fixture by fixture, and the rig is signed off only when every fixture sits on one unbroken daisy chain. Fixtures are numbered 0 upward, and links[i] lists every fixture cabled directly to fixture i. A cable shows up in both of the lists it joins, and a list may repeat a cable, which still counts as that one cable. Return true when the rig forms exactly one chain: no fixture carries more than two cables, exactly two fixtures carry a single cable and sit at the ends, and every fixture is reachable from every other by walking cables. A rig holding one fixture and no cable counts as a chain. A fixture cabled to itself is a wiring fault, so return false, and an empty rig returns false as well.
forms_one_daisy_chain(links: list[list[int]]) → bool[[[1],[0,2],[1]]]outtrue[[[1,2],[0,2],[0,1]]]outfalse[[[1,2,3],[0],[0],[0]]]outfalseState 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.
[[[1],[0,2],[1]]]truenot run yetsample[[[1,2],[0,2],[0,1]]]falsenot run yetsample[[[1,2,3],[0],[0],[0]]]falsenot run yetsample