[Python] RECURSION Easy & short
Redundant Connection\nIdea\n We assume there is a tree, we add nodes from the edges one by one \n We check for edge u & v :-\n 1.  If both have same root then i
# Redundant Connection\n**Idea**\n* We assume there is a tree, we add nodes from the **edges** one by one \n* We check for **edge** `u & v` :-\n* 1.  If both have same root then it forms a loop and we have to return this **edge**\n* 2.  If not have then add that edge to tree\n\n[Note] Here `recur` function will return the root for every node `u & v`. \nIn for loop :-\n* Storing roots of u & v in x & y respectively\n* if both u & v have same roots then return u & v\n* if u node is not already added then connect v to u\n* if v node in not already added then connect u to v\n* if both nodes are added but have different roots then connect root of v to root of u\n\n\n**Complexity**\n* `Time Complexity` -> `O(n*n)` , where n is number of **edges**\n* `Space Complexity` -> `O(n)`, for storing tree path in `w`\n\n```\nclass Solution:\n    def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:\n        w = [*range(len(edges)+1)]\n        def recur(x):\n            if w[x] == x:\n                return x\n            return recur(w[x])\n        for u, v in edges:\n            x, y = recur(u), recur(v)\n            if x == y: return [u, v]\n            elif w[u] == u: w[u] = v\n            elif w[v] == v: w[v] = u\n            else: w[x] = y\n```\n\n*please upvote if you like the solution and comment if have queries*
['Recursion', 'Python']