Java || Striver DSU Implementation || Explanation With Comments || Intution
Java Solution :\n\nclass DisjointSet {\n    \n\t// Parent Array to hold smallest character linked with current character\n    int[] par = new int[26];\n    \n  
**Java Solution :**\n```\nclass DisjointSet {\n    \n\t// Parent Array to hold smallest character linked with current character\n    int[] par = new int[26];\n    \n    DisjointSet() {\n        for(int i = 0; i < 26; i++) par[i] = i;\n    }\n    \n\t// Compressend Find parent Function\n    int findPar(int x) {\n        \n\t\t// If x is parent of himself, return\n        if(par[x] == x) return x;\n        \n\t\t// Else find its parent update its parent array and return\n        return par[x] = findPar(par[x]);\n        \n    }\n    \n\t// Union just updates the parent\n    void union(int x, int y) {\n        \n        x = findPar(x);\n        y = findPar(y);\n        \n\t\t// Lexicographically smaller character will become the parent\n        if(x < y) par[y] = par[x];\n        else par[x] = par[y];\n    \n    }\n    \n}\n\nclass Solution {    \n    \n    public String smallestEquivalentString(String s1, String s2, String baseStr) {\n        \n        DisjointSet ds = new DisjointSet();\n        \n        for(int i = 0; i < s1.length(); i++) {\n            \n            int x = (int)(s1.charAt(i) - \'a\');\n            int y = (int)(s2.charAt(i) - \'a\');\n            \n\t\t\t// Making a union of all given equivalent charactrers\n            ds.union(x, y);\n            \n        }\n        \n\t\t// Adding parent of each character from the Base String\n\t\t// Parent = smallest equivalent character linked with it !!!\n        StringBuilder ans = new StringBuilder("");\n        for(int i = 0; i < baseStr.length(); i++) {\n            char c = (char)(\'a\' + ds.findPar((int)(baseStr.charAt(i) - \'a\')));\n            ans.append(c);\n        }\n        \n        return ans.toString();\n    }\n\n}\n```\n\nHope it would have Helped !!!\n**Thank You !!!**
['Java']