Simple union find with a twist in union
\nclass Solution {\n    \n    private int[] parent = new int[26];\n    \n    public String smallestEquivalentString(String A, String B, String S) {\n        Str
```\nclass Solution {\n    \n    private int[] parent = new int[26];\n    \n    public String smallestEquivalentString(String A, String B, String S) {\n        StringBuilder sb = new StringBuilder();\n        for (int i = 0;i < parent.length;i++) parent[i] = i;\n        for (int i = 0;i < A.length();i++) {\n            char ch1 = A.charAt(i);\n            char ch2 = B.charAt(i);\n            union(ch1 - \'a\', ch2 - \'a\');\n        }\n        for (char ch:S.toCharArray()) {\n            int p = find(ch - \'a\');\n            sb.append((char) (p + \'a\'));\n        }\n        return sb.toString();\n    }\n    \n    private void union(int ch1, int ch2) {\n        int p1 = find(ch1);\n        int p2 = find(ch2);\n        if (p1 < p2) {\n            parent[p2] = p1; \n        } else {\n            parent[p1] = p2;\n        }\n        \n    }\n    \n    private int find(int x) {\n        if (parent[x] != x) {\n            parent[x] = find(parent[x]);\n        }\n        return parent[x];\n    }                                                       \n}\n```
[]