Functional JavaScript 1-liner DSU 0ms
IntuitionWe can use edges.find to return edge that creates a cycle in a graph.
Edge creates cycle if both ends already belong to the same connected component (g
# Intuition
We can use `edges.find` to return edge that creates a cycle in a graph.
Edge creates cycle if both ends already belong to the same connected component (group of connected nodes).
Initially all nodes are in their own group which we will give number equal to node's number.
We can use mapping to merge groups. For every new edge, one group number becomes base number for merged group and we map other group's number to this base number.

```
findRedundantConnection = (
    edges,
    $ = x => $[x] ? $[x] = $($[x]) : x
) => edges.find(([a, b]) => (a = $(a)) == ($[a] = $(b)))
```
Time: $$O(n)$$
Space: $$O(n)$$

![Screenshot 2025-01-28 at 6.41.13 PM.png](https://assets.leetcode.com/users/images/0f6551d0-afc0-4e1e-8c21-116b4289ad5f_1738118513.47512.png)

['Union Find', 'Recursion', 'JavaScript']