Easy C++ solution using union find || Beat 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nAs given in the question, we solve it using put the same relation of character in one t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs given in the question, we solve it using put the same relation of character in one type of group.So because of this we use union method.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSo the approach is simple we traverse both string s1 and s2 and put the same type or relation of character or letter in one group and make parent of these character to smallest alphabet letter So it will help in lexiographical order.\n\n\n**Here is my code**\n# Code\n```\nclass Solution {\npublic:\n    vector<int> parent,rank;\n    int findpar(int node){\n        if(node==parent[node]) return node;\n\n        return findpar(parent[node]);\n    }\n    void uni(int u,int v){\n        u=findpar(u);\n        v=findpar(v);\n        if(u==v) return;\n        if(u<v){\n            parent[v]=u;\n        }\n        else{\n            parent[u]=v;\n        }\n        return;\n    }\n    string smallestEquivalentString(string s1, string s2, string basestr) {\n        parent.resize(26,0);\n        rank.resize(26,0);\n        for(int i=0;i<26;i++) parent[i]=i;\n        for(int i=0;i<s1.size();i++){\n            int a=s1[i]-\'a\';\n            int b=s2[i]-\'a\';\n            uni(a,b);\n        }\n        for(int i=0;i<basestr.size();i++){\n            int a=findpar(basestr[i]-\'a\');\n            basestr[i]=a+\'a\';\n        }\n        return basestr;\n    }\n};\n```\nplease upvote if you like it.\n\n![leetcode.jpg](https://assets.leetcode.com/users/images/afde0822-e3ea-45d2-b8bd-4a78e2f16b45_1673704091.5924892.jpeg)\n\n\n
['Union Find', 'C++']