Solution without Union Find
Intuition\n Describe your first thoughts on how to solve this problem. \nMapping\n\n# Approach\n Describe your approach to solving the problem. \nMapping of cha
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMapping\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMapping of characters with sets.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        map<char, set<char> > m;\n        for(int i=0;i<s1.length();i++){\n            m[s1[i]].insert(s1[i]);\n            m[s1[i]].insert(s2[i]);\n            m[s2[i]].insert(s1[i]);\n            m[s2[i]].insert(s2[i]);\n        }\n        for(auto a:m){\n            // cout<<a.first<<" - ";\n            char ch = a.first;\n            for(auto b:a.second){\n                // cout<<b<<" ";\n                for(auto x:m[b]){\n                    m[ch].insert(x);\n                    m[x].insert(ch);\n                }\n            }\n            // cout<<endl;\n        }\n        for(auto a:m){\n            // cout<<a.first<<" - ";\n            char ch = a.first;\n            for(auto b:a.second){\n                // cout<<b<<" ";\n                for(auto x:m[b]){\n                    m[ch].insert(x);\n                    m[x].insert(ch);\n                }\n            }\n            // cout<<endl;\n        }\n\n        // for(auto a:m){\n        //     cout<<a.first<<" - ";\n        //     for(auto b:a.second){\n        //         cout<<b<<" ";\n        //     }\n        //     cout<<endl;\n        // }\n\n        for(int i=0;i<baseStr.length();i++){\n            while(m[baseStr[i]].size() > 0 && baseStr[i] != *m[baseStr[i]].begin()){\n                baseStr[i] = *m[baseStr[i]].begin(); \n            }\n        }\n        return baseStr;\n    }\n};\n```
['C++']