Java || C++ || JavaScript || Beats 100% || Union-Find || Concise and Clean code
Union-Find Beats 100% - \n\njava []\nclass Solution {\n    int[] parent;\n    public String smallestEquivalentString(String s1, String s2, String baseStr) {\n  
### Union-Find Beats 100% - \n\n``` java []\nclass Solution {\n    int[] parent;\n    public String smallestEquivalentString(String s1, String s2, String baseStr) {\n        parent = new int[26];\n        for(int i=0;i<26;i++)\n            parent[i]=i;\n        for(int i=0;i<s1.length();i++){\n            int u = find(s1.charAt(i)-\'a\');\n            int v = find(s2.charAt(i)-\'a\');\n            if(u<v)\n              parent[v]=u;\n            else if(u>v)\n              parent[u]=v;\n        }\n        StringBuilder sb = new StringBuilder();\n        for(int i=0;i<baseStr.length();i++)\n            sb.append((char)(find(baseStr.charAt(i)-\'a\')+\'a\'));\n        return sb.toString();\n    }\n\n    private int find(int u){\n        return parent[u]==u? u:find(parent[u]);\n    }\n}\n```\n``` C++ []\nclass Solution {\n    int parent[26];\npublic:\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        for (int i = 0; i < 26; i++) {\n            parent[i] = i;\n        }\n        for (int i = 0; i < s1.length(); i++) {\n            int u = find(s1[i] - \'a\');\n            int v = find(s2[i] - \'a\');\n            if (u < v) {\n                parent[v] = u;\n            } else if (u > v) {\n                parent[u] = v;\n            }\n        }\n        for (int i = 0; i < baseStr.length(); i++) {\n            baseStr[i]= (char)(find(baseStr[i] - \'a\') + \'a\');\n        }\n        return baseStr;\n    }\n\n    int find(int u) {\n        return parent[u] == u ? u : find(parent[u]);\n    }\n};\n\n```\n``` javascript []\nvar smallestEquivalentString = function(s1, s2, baseStr) {\n    let parent = new Array(26).fill(0);\n    for (let i = 0; i < 26; i++) {\n        parent[i] = i;\n    }\n    for (let i = 0; i < s1.length; i++) {\n        let u = find(s1.charCodeAt(i) - \'a\'.charCodeAt(0),parent);\n        let v = find(s2.charCodeAt(i) - \'a\'.charCodeAt(0),parent);\n        if (u < v) {\n            parent[v] = u;\n        } else if (u > v) {\n            parent[u] = v;\n        }\n    }\n    let result="";\n    for (let i = 0; i < baseStr.length; i++) {\n        result += String.fromCharCode(find(baseStr.charCodeAt(i) - \'a\'.charCodeAt(0),parent) + \'a\'.charCodeAt(0));\n    }\n    return result;\n};\n\nfunction find(u,parent) {\n    return parent[u] === u ? u : find(parent[u],parent);\n};\n```\n\n### Brute Force(Java) Beats 90% Explained- \nhttps://leetcode.com/problems/lexicographically-smallest-equivalent-string/solutions/3047864/java-solution-brute-force-beats-90-hashtable-set-with-comments/
['Union Find', 'C++', 'Java', 'JavaScript']