Union find using unordered_map
Instead of using a vector, simple use of map to remember the parents \n\nDry run :- \n\n\n--- \n\n\n\n\nFinally We use the map to build baseStr\nc++\nclass Solu
Instead of using a vector, simple use of map to remember the parents \n\nDry run :- \n![image](https://assets.leetcode.com/users/images/b37c2628-7633-411b-8d69-2d0b1f73f316_1673676804.6303382.png)\n\n--- \n\n![image](https://assets.leetcode.com/users/images/698e4776-7558-4d30-9933-b546e760a547_1673676817.3370528.png)\n\n\nFinally We use the map to build baseStr\n```c++\nclass Solution {\npublic:\n    unordered_map<char,char> par;\n    int find(int x){\n        if(par[x] == 0) return x;\n        int temp = par[x];\n        while(par[temp]){\n            temp = par[temp];\n        }\n        return temp;\n    } \n    void Union(int x, int y) {\n        x = find(x);\n        y = find(y);   \n        if (x != y) {\n            par[max(x, y)] = min(x , y);\n        }\n    }\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        for (int i = 0; i < s1.size(); ++i) \n            Union(s1[i], s2[i]);\n        for(char& c: baseStr) c = find(c); \n        return baseStr;\n    }\n};\n```
['Union Find', 'C']