Redundant Connection in RUBY!
IntuitionWhen I first saw this problem, I realized it's about finding a cycle in an undirected graph. Since we need to find the last edge that creates a cycle,
# Intuition
When I first saw this problem, I realized it's about finding a cycle in an undirected graph. Since we need to find the last edge that creates a cycle, Union-Find (Disjoint Set) would be perfect as we can process edges in order and detect when an edge connects two already-connected components.

# Approach
I implemented the solution using Union-Find with path compression:

1. **Initialize Union-Find**:
   - Create parent array where each node is its own parent initially
   - Size is n+1 since nodes are 1-indexed

2. **Process Each Edge**:
   - For each edge [x,y]:
     - Find parents of both nodes
     - If parents are same, we found a cycle
     - Otherwise, union the components

3. **Path Compression**:
   - Implement find with path compression
   - Makes subsequent operations more efficient

# Complexity
- Time complexity: $$O(N\alpha(N))$$
  - N is number of nodes
  - α is inverse Ackermann function
  - Nearly constant time per operation

- Space complexity: $$O(N)$$
  - Parent array stores N elements
  - Recursion stack for find operations

# Code
```ruby
def find_redundant_connection(edges)
    n = edges.length
    parent = Array.new(n + 1) { |i| i }
    
    def find(parent, x)
        if parent[x] != x
            parent[x] = find(parent, parent[x])
        end
        parent[x]
    end
    
    def union(parent, x, y)
        parent[find(parent, x)] = find(parent, y)
    end
    
    edges.each do |x, y|
        px, py = find(parent, x), find(parent, y)
        if px == py
            return [x, y]
        end
        union(parent, x, y)
    end
end
```
['Ruby']