Union Find Solution Java
\nclass Solution {\n    public String smallestEquivalentString(String A, String B, String S) {\n        int[] graph = new int[26];\n        for(int i = 0; i < 2
```\nclass Solution {\n    public String smallestEquivalentString(String A, String B, String S) {\n        int[] graph = new int[26];\n        for(int i = 0; i < 26; i++) {\n            graph[i] = i;\n        }\n        for(int i = 0; i < A.length(); i++) {\n            int a = A.charAt(i) - \'a\';\n            int b = B.charAt(i) - \'a\';\n            int end1 = find(graph, b);\n            int end2 = find(graph, a);\n            if(end1 < end2) {\n                graph[end2] = end1;\n            } else {\n                graph[end1] = end2;\n            }\n        }\n        StringBuilder sb = new StringBuilder();\n        for(int i = 0; i < S.length(); i++) {\n            char c = S.charAt(i);\n            sb.append((char)(\'a\' + find(graph, c - \'a\')));\n        }\n        return sb.toString();\n    }\n    \n    private int find(int[] graph, int idx) {\n        while(graph[idx] != idx) {\n            idx = graph[idx];\n        }\n        return idx;\n    }\n}\n```
[]