👉🏽 python3 || Union find with char groups
The usual union-find is thinking about belonging to groups and in this case, assume there can be 26 groups. \n\n```\nclass Solution:\n    def smallestEquivalent
The usual union-find is thinking about belonging to groups and in this case, assume there can be 26 groups. \n\n```\nclass Solution:\n    def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:\n        d = {\'a\': \'a\', \'b\': \'b\', \'c\': \'c\', \'d\': \'d\', \'e\': \'e\', \'f\': \'f\', \'g\': \'g\', \'h\': \'h\', \'i\': \'i\', \'j\': \'j\', \'k\': \'k\', \'l\': \'l\', \'m\': \'m\', \'n\': \'n\', \'o\': \'o\', \'p\': \'p\', \'q\': \'q\', \'r\': \'r\', \'s\': \'s\', \'t\': \'t\', \'u\': \'u\', \'v\': \'v\', \'w\': \'w\', \'x\': \'x\', \'y\': \'y\', \'z\': \'z\'}\n        \n        def find(char):\n            if char != d[char]:\n                d[char] = find(d[char])\n            return d[char]\n        \n        def update(char, value):\n            if char != d[char]:\n                update(d[char], value)\n            d[char] = value\n            \n        for a,b in zip(s1, s2):\n            p,q = find(a), find(b)\n            \n            if p > q:\n                update(p, q)\n            else:\n                update(q, p)\n\n        return "".join([find(d[i]) for i in baseStr])\n        \n
['Union Find', 'Python', 'Python3']