✅ Easy C++ Solution Using Array (Without Union-Find) ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to associate every lowercase english alphabet to it\'s lexicographically smalle
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to associate every lowercase english alphabet to it\'s lexicographically smallest equivalent using the given properties of equality and transitivity.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We define an array of size 26 to map each lowercase alphabet to its lexicographically smallest equivalent\n2. Initialize this array with the char itself\n3. Now for every index of string `s1` and `s2`, we replace all elements pointing to the greater char between `lowestEquivalent of s1[i]` and `lowestEquivalent of s2[i]` with the smaller one.\n\n#### Why does this work?\n\nAfter every step, we map all elements that were pointing to the greater equivalent to the smaller one (using properties of transitivity). Since we only have 26 alphabets, this can be done in roughly constant time.\n\neg: `s1 = "ab"` and `s2 = "bc"`\nConsider the mapped array `lowest` (storing char to it\'s lowest equivalent) to be:\n```\na = a\nb = b\nc = c\n```\n\n#### At index = 0: `(a == b)`\n```\na = a\nb = lowest[a] = a\nc = c\n```\n\n#### At index = 1: `(b == c)`\n```\na = a\nb = a\nc = lowest[b] = a\n```\n\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n * 26)$$ = $$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(26)$$\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        char ch[26];\n        for (int i=0; i<26; i++)\n            ch[i] = \'a\' + i;\n\n        for (int i=0; i<s1.size(); i++) {\n            char toReplace = max(ch[s1[i]-\'a\'], ch[s2[i]-\'a\']);\n            char replaceWith = min(ch[s1[i]-\'a\'], ch[s2[i]-\'a\']);\n            for (int i=0; i<26; i++)\n                if (ch[i] == toReplace)\n                    ch[i] = replaceWith;\n        }\n        \n        for (int i = 0; i<baseStr.size(); i++)\n            baseStr[i] = ch[baseStr[i]-\'a\'];\n\n        return baseStr;\n    }\n};\n```
['Array', 'C++']