C++|Hash Map | Simple(without Union Find)
Intuition\n Describe your first thoughts on how to solve this problem. \nMany are trying to do this by using Union Find but I want to share the idea of using ma
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMany are trying to do this by using Union Find but I want to share the idea of using map. If we use a hash map of 26 .Which we will initiliaze with a-z  then we have just compare the incoming two letters from the two strings and update the map with minimum among them. \nAt last update the baseStr by our hash map characters .\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- `mx=max(mp[s1[i]-\'a\'],mp[s2[i]-\'a\'])` -->gives that character which we have to update \n- `mn=min(mp[s1[i]-\'a\'],mp[s2[i]-\'a\'])` --> gives that character with which we will update \n- beacuse we want lexographically smallest so update max with min.\n- The map will track  those who where updated because it will now store the minimum and will compare that minimum stored with other incoming characters.\n- e.g first compare `r,k` change `r with k` then k will be stored at r\'s position and if in future there is `r,s` rth position will have k so it will compare `k and s` and thus change `s to k` as well . \n- So in this manner it will return lexographically smallest string possible\n# Complexity\n- Time complexity:O(n*26)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(26)\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        string ans;\n        int n=s1.length();\n        int mp[26];\n        for(int i=0;i<26;i++){\n          mp[i]=\'a\'+i;\n        }\n        for(int i=0;i<n;i++){\n            int mx=max(mp[s1[i]-\'a\'],mp[s2[i]-\'a\']);\n             int mn=min(mp[s1[i]-\'a\'],mp[s2[i]-\'a\']);\n             for(int i=0;i<26;i++){\n                 if(mp[i]==mx)mp[i]=mn;\n             }\n        }\n        for(int i=0;i<baseStr.size();i++){\n            baseStr[i]=mp[baseStr[i]-\'a\'];\n        }\n        return baseStr;\n    }\n};\n```
['Hash Table', 'Union Find', 'C++']