Using DSU
\n\n# Disjoint Set Union(DSU)|Simple C++ code|Beginner Friendly\n\n\n\n\n# Code\n\nclass Solution {\npublic:\nint par[125];\nint sz[125];\n\n\nvoid makeset(int 
\n\n# Disjoint Set Union(DSU)|Simple C++ code|Beginner Friendly\n\n\n\n\n# Code\n```\nclass Solution {\npublic:\nint par[125];\nint sz[125];\n\n\nvoid makeset(int i)\n{\n    par[i] = i;\n    sz[i] = 1;\n   \n}\nint find(int i)\n{\n    if (par[i] == i)\n    {\n\n        return i;\n    }\n    return par[i] = find(par[i]);\n}\nvoid set_union(int a, int b)\n{\n    a = find(a);\n    b = find(b);\n\n    if (a != b)\n    {\n        if(a>b)\n        swap(a,b);\n        sz[a] += sz[b];\n        par[b] = a;\n    }\n \n}\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        int n=s1.size();\n        for(char ch=\'a\';ch<=\'z\';ch++)\n        {\n            makeset(ch);\n        }\n        for(int i=0;i<n;i++)\n        {\n            int u=s1[i];\n            int v=s2[i];\n            set_union(u,v);\n        }\n        string ans="";\n        for(int i=0;i<baseStr.size();i++)\n        {\n            int val=baseStr[i];\n            char ch=find(val);\n            ans+=ch;\n            \n          \n        }\n        return ans;\n\n    }\n};\n```
['C++']