📌 C++ || Beats - 100% 💯💯|| Explained Using Disjoint Set Union
Intuition\nWe can just apply DisjointSet Union.\n\n    Runtime - 100%\uD83D\uDD25 \n\n# Code\n\nclass DisjointSet{\npublic:\n    vector<int> size, parent, rank;
# Intuition\nWe can just apply DisjointSet Union.\n\n    Runtime - 100%\uD83D\uDD25 \n\n# Code\n```\nclass DisjointSet{\npublic:\n    vector<int> size, parent, rank;\n    DisjointSet(int n){\n        rank.resize(n+1, 0);\n        size.resize(n+1, 0);\n        parent.resize(n+1);\n        for(int i=0; i<=n; i++){\n            parent[i] = i;\n        }\n    }\n    int findUPar(int node){\n        if(node == parent[node]){\n            return node;\n        }\n        return parent[node] = findUPar(parent[node]);\n    }\n    void UnionByRank(int u, int v){\n        int ulp_u = findUPar(u);\n        int ulp_v = findUPar(v);\n        if(ulp_u == ulp_v){\n            return;\n        }\n        if(rank[ulp_u]<rank[ulp_v]){\n            parent[u] = ulp_v;\n        }\n        else if(rank[ulp_u]>rank[ulp_v]){\n            parent[v] = ulp_u;\n        }\n        else{\n            parent[v] = ulp_u;\n            rank[ulp_u]++;\n        }\n    }\n    void UnionBySize(int u, int v){\n        int ulp_u = findUPar(u);\n        int ulp_v = findUPar(v);\n        if(ulp_u == ulp_v){\n            return;\n        }\n        if(ulp_u>ulp_v){\n            parent[ulp_u] = parent[ulp_v];\n            size[ulp_v] += size[ulp_u];\n        }\n        else{\n            parent[ulp_v] = parent[ulp_u];\n            size[ulp_u] += size[ulp_v];\n        }\n    }\n};\nclass Solution {\npublic:\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        int V = s1.length();\n        DisjointSet ds(26);\n        for(int i=0; i<V; i++){\n            int u = s1[i]-\'a\';\n            int v = s2[i]-\'a\';\n            ds.UnionBySize(u,v);\n        }\n        string ans;\n        int n = baseStr.length();\n        for(int i=0; i<n; i++){\n            ans+=(char)(ds.findUPar(baseStr[i]-\'a\') + \'a\');\n        }\n        return ans;\n    }\n};\n```\n#  If you like the solution and understand it then Please Upvote.\u2B06\uFE0F\u2764\uFE0F \n\t* PEACE OUT LUV\u270C\uFE0F*
['Union Find', 'C++']