JavaScript Union Find and DFS solutions
\nvar findRedundantConnection = function(edges) {\n    const dsu = new UnionFind(edges.length);\n    for(let edge of edges) {\n        const [u,v] = edge;\n    
```\nvar findRedundantConnection = function(edges) {\n    const dsu = new UnionFind(edges.length);\n    for(let edge of edges) {\n        const [u,v] = edge;\n        if(!dsu.union(u, v)) {\n            return edge;\n        }\n    }\n    return [];\n};\n\nclass UnionFind {\n    \n    constructor(size) {\n        this.parent = new Array(size);\n        for(let i = 0; i < size; i++) {\n            this.parent[i] = i;\n        }\n        this.rank = new Array(size);\n    }\n    \n    find(x) {\n        if(this.parent[x] !== x) {\n            this.parent[x] = this.find(this.parent[x]);\n        }\n        return this.parent[x];\n    }\n    \n    union(x,y) {\n        let xr = this.find(x);\n        let yr = this.find(y);\n        if(xr === yr) {\n            return false; // already have the same parent\n        } else if(this.rank[xr] < this.rank[yr]) {\n            this.parent[xr] = yr;\n        } else if(this.rank[xr] > this.rank[yr]) {\n            this.parent[yr] = xr;\n        } else {\n            // same height\n            this.parent[yr] = xr;\n            this.rank[xr]++;\n        }\n        return true;\n    }\n}\n```\n\nDFS speed at 0% percentile lmao :D\n```\nconst adjList = {};\n\nfunction dfs(source, target, visited) {\n\n\tif(source === target) {\n\t\treturn true;\n\t}\n\n\tif(!visited[source]) {\n\t\tvisited[source] = true;\n\t}\n\n\tif(adjList[source] === undefined) return false;\n\n\tfor(let nei of adjList[source]) {\n\t\tif(visited[nei]) {\n\t\t\tcontinue;\n\t\t}\n\t\tif(dfs(nei, target, {...visited})) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}  \n\nfor(let edge of edges) {    \n\tconst [u,v] = edge;\n\tif(dfs(u,v,{})) {\n\t\treturn [u,v];\n\t}\n\tif(!adjList[u]) {\n\t\tadjList[u] = [];\n\t}\n\tif(!adjList[v]) {\n\t\tadjList[v] = [];\n\t}\n\tadjList[u].push(v);\n\tadjList[v].push(u);\n}\n```
[]