Simple Python Solution with explanation 🔥  ||  beats 96.5%
Approach\n\n Create two maps char_group and char_map to track characters which are equivalent:\n    \n    \n\n    char_group is a map of groups of characters wh
# Approach\n\n* Create two maps `char_group` and `char_map` to track characters which are equivalent:\n    \n    ![Untitled-2023-01-11-1852(11).png](https://assets.leetcode.com/users/images/4b6151d4-d967-4797-a7f9-34ce033bb30c_1673700018.0016778.png)\n\n    `char_group` is a map of groups of characters which are equivalent, eg: \'a\', \'d\', \'e\' are equivalent with group_id as 0.\n\n    \n    ![Untitled-2023-01-11-1852(12).png](https://assets.leetcode.com/users/images/fdc19f3f-08c8-4d96-bca9-786c32fc8f6e_1673700041.7656307.png)\n\n    `char_map`: is a map of characters to the equivalent group it belongs, eg: \'a\', \'d\', \'e\' belong to group_id 0. If the character doesn\'t belong to any group, the default value is -1.\n\n* Sort `char_group` lexicographically (since we need only the smallest lexicographic character, we can optimise this by selecting only the smallest character).\n\n* For `basestr` for each character check using `char_map` which equivalent group the character belongs to and select the smallest lexicographic character (0th index since we have sorted this).\n\n\n# Complexity\n`n` => len(s1)\n`m` => len(baseStr)\n\n- Time complexity:\n$$O(m + n*26 + 26*26)$$ => $$O(m + n)$$\n\n- Space complexity:\n$$O(m + (26 + 26*26))$$ => $$O(m))$$\n\n    `char_map` and `char_group` are considered constant since `char_map` and `char_group` can have 26 max keys, and for each key in `char_group` it can have value of list of max 26 members\n\n# Code\n``` python []\nclass Solution:\n    def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:\n        char_group = {}\n        idx = 0\n        char_map = {chr(97 + i): -1 for i in range(26)}\n\n        for i in range(len(s1)):\n            if s1[i] == s2[i]:\n                continue\n\n            if char_map[s1[i]] == -1 and char_map[s2[i]] == -1:\n                char_map[s1[i]] = char_map[s2[i]] = idx\n                char_group[idx] = [s2[i], s1[i]]\n                idx += 1\n            elif char_map[s1[i]] == -1:\n                char_map[s1[i]] = char_map[s2[i]]\n                char_group[char_map[s2[i]]].append(s1[i])\n            elif char_map[s2[i]] == -1:\n                char_map[s2[i]] = char_map[s1[i]]\n                char_group[char_map[s1[i]]].append(s2[i])\n            elif char_map[s1[i]] != char_map[s2[i]]:\n                for c in char_group[char_map[s2[i]]]:\n                    char_map[c] = char_map[s1[i]]\n                    char_group[char_map[s1[i]]].append(c)\n\n        # sort each group\n        for k in char_group.keys():\n            char_group[k].sort()\n\n        ans = ""\n        for c in baseStr:\n            if char_map[c] == -1:\n                ans += c\n            else:\n                ans += char_group[char_map[c]][0]\n\n        return ans\n\n\n```
['Hash Table', 'Python', 'Python3']