Gamified challenge · Union-find
A network has nodes 1…n and exactly n cables; edges[i] = [u, v] joins u and v (cables work both ways). Without one of them the network would be a tree: connected, with no loops.
Write redundant(edges) that returns the cable to remove so that a tree is left. If several cables would do (any cable on the loop), return the one that comes last in edges. Return it as [u, v]; either order of the two ends is fine.
Example: [[1, 2], [1, 3], [2, 3]] → [2, 3]. All three cables are on the loop, and [2, 3] is listed last.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google