🏆 Easy C++ Solution 🏆||🚀 Beats 100% 🚀|| Fully Explained🚀
Consider!\uD83D\uDC4D\uD83D\uDC4D\n\n                    # Please Upvote If You Find It Helpful.\n\n# Approach\nThe provided code is an implementation of a func
**Consider!\uD83D\uDC4D\uD83D\uDC4D**\n```\n                    # Please Upvote If You Find It Helpful.\n```\n# Approach\nThe provided code is an implementation of a function "smallestEquivalentString" that takes three strings as input: s1, s2, and baseStr. The function first initializes an array "temp" of size 26 (to store the equivalent characters)\n\nThe function then iterates through the characters of s1 and s2, using a union-find algorithm to find the smallest equivalent characters for the corresponding characters in s1 and s2 and stores them in the "temp" array. The find function is used to find the representative element of the set to which the current element belongs and the union function is used to union the sets of two elements.\n\nThen, it iterates through the characters of baseStr and appends the smallest equivalent character for each character to the "ans" string, which is returned at the end.\n\nThe function starts by initializing the elements of the array "temp" to its index. For each i-th character of s1 and s2, the union function is called to merge the set containing s1[i] and the set containing s2[i].\n\nThen, for each character in the baseStr, the find function is used to find the representative element of the set containing the character, this representative element is added to the ans string.\n\nFinally, the ans string which contains the smallest equivalent string is returned.\n<!-- Describe your approach to solving the problem. -->\n\n\n# Code\n```\nclass Solution {\n    int temp[26]; \npublic:\n    // Find function to find the representative element of the set containing the character\n    int find(int ch){\n        return ch == temp[ch] ? ch : temp[ch] = find(temp[ch]);\n    }\n    // Union function to merge the set containing x and the set containing y\n    void unin(int x, int y){\n        x = find(x);\n        y = find(y);\n        if(x < y)\n            temp[y] = x;\n        else\n            temp[x] = y;\n    }\n\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        string ans;\n        // Initialize all elements of temp array to its index\n        for(int i=0;i<26;i++) temp[i] = i;\n        // Iterate through s1 and s2 and union the sets containing the corresponding characters\n        for(int i=0;i<s1.size();i++)\n            unin(s1[i]-\'a\', s2[i]-\'a\');\n        // Iterate through baseStr and find the representative element of the set containing each character\n        // and append it to the ans string\n        for(char it : baseStr)\n            ans += (char)(find(it - \'a\') + \'a\');\n        return ans;\n    }\n};\n\n```\n\n```\n                # Please Upvote If You Find It Helpful.\n```\nLet\'s connect on [Linkedin](https://www.linkedin.com/in/naman-agarwal-0551aa1aa/)
['String', 'Union Find', 'Recursion', 'C++']