MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / findRedundantConnection

Method findRedundantConnection

RedundantConnection.java:4–14  ·  view source on GitHub ↗
(int[][] edges)

Source from the content-addressed store, hash-verified

2 int totalNodes;
3 // 1 based 1,2,3
4 public int[] findRedundantConnection(int[][] edges) {
5 totalNodes = edges.length;
6 int res[] = new int[2];
7 DisjointSet dsu = new DisjointSet(totalNodes);
8 for (int[] edge: edges) {
9 if (!dsu.unionBySize(edge[0]-1, edge[1]-1)) {
10 return edge;
11 }
12 }
13 return res;
14 }
15}
16
17public class DisjointSet {

Callers

nothing calls this directly

Calls 1

unionBySizeMethod · 0.95

Tested by

no test coverage detected