Simple Implementation in python using union find
Hi guys. hope you are safe and healthy !\nThis is a simple code \nHere i have found something interesting\nWhen i initialise my self.parent = [0] len it is givi
Hi guys. hope you are safe and healthy !\nThis is a simple code \nHere i have found something interesting\nWhen i initialise my self.parent = [0]* len it is giving me 40% while when i do this [-1]* len then i am getting 98% in time\n[-1] idea given by @arnav3\nHope this will help\n\n```\n    def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:\n        # using union find\n        \n        self.parent = [-1]*(len(edges)+1)   # -1 is giving me 98% time \n\t\t# self.parent = [0]*(len(edges)+1)   # 0 is giving me 40% time \t\n        \n        def find(x):\n            while self.parent[x] > 0:\n                x = self.parent[x]\n            return x     \n        \n        def union(x,y):\n            root_x = find(x)\n            root_y = find(y)\n        \n            if root_x == root_y:\n                return False\n            else:\n                self.parent[root_x] = root_y\n                return True\n            \n        for u,v in edges:\n            if not union(u,v):\n                return [u,v]\n        \n```
['Union Find', 'Python', 'Python3']