Redundant Connection
A tree on labels 1..n received one additional edge. Return an edge whose removal restores a tree; when several work, return the one appearing latest in the supplied edge array.
Example 1
edges = [[1,2],[2,3],[1,3]][1,3]Explanation
The final edge [1,3] closes the triangle; removing it restores a tree.
Example 2
edges = [[1,2],[2,3],[3,4],[1,4],[1,5]][1,4]Explanation
[1,4] closes cycle 1-2-3-4-1 and is its latest edge; node 5 stays attached.
Example 3
edges = [[1,3],[3,2],[2,1]][2,1]Explanation
[2,1] closes the three-node cycle and is the latest removable edge.
Constraints
- 3 <= n <= 1000
- There are n distinct undirected edges
- No self-loops
Function contract
findRedundantConnectionArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[[1,2],[2,3],[1,3]]