Code RoomVerify daisy chain rig
EasyPrep Room Coding #4820

Verify daisy chain rig

CodingAlgorithms & data structuresEntry–Mid~16 min

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.

Implement
forms_one_daisy_chain(links: list[list[int]]) → bool
Examples
in[[[1],[0,2],[1]]]outtrue
in[[[1,2],[0,2],[0,1]]]outfalse
in[[[1,2,3],[0],[0],[0]]]outfalse
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.

0:00 of about 16 min
InputExpectedGot
[[[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