🔥 DSU Explained 🔥
Please Upvote if you like the solution \u2B06\uFE0F\n\n# Code\n\nclass DisjointSet:\n    def __init__(self):\n        self.parent = {}\n        # intitial every
# Please Upvote if you like the solution \u2B06\uFE0F\n\n# Code\n```\nclass DisjointSet:\n    def __init__(self):\n        self.parent = {}\n        # intitial every one if parent of themselves\n        # making self as parent initial\n        for letter in string.ascii_lowercase:\n            self.parent[letter] = letter\n    \n    def findParent(self,node):\n            while  node!= self.parent[node]:\n                node = self.parent[node]\n\n            return node\n        \n    def doUnion(self, a,b):\n        # find ultimate parent of a and b\n        ulp_a = self.findParent(a)\n        ulp_b = self.findParent(b)\n    \n        # assign minimum as ultimate parent of both a and b\n        self.parent[ulp_a] = self.parent[ulp_b] = min(ulp_a, ulp_b)\n    \n\nclass Solution:\n    def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:\n        ds = DisjointSet()\n        for i in range(len(s1)):\n            ds.doUnion(s1[i], s2[i])\n\n        ans = ""\n        for c in baseStr:\n            ans += ds.parent[ds.findParent(c)]\n        return ans\n\n```
['Union Find', 'Python', 'Python3']