💯✅ 100% | 0MS | STREAM VS SB | 2 WAYS | CONCISE | PROOF 💯⬆️
UPVOTE PLS\n Describe your first thoughts on how to solve this problem. \n\n# \n Describe your approach to solving the problem. \n\n\n# Complexity\n- Time compl
# UPVOTE PLS\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# \n<!-- Describe your approach to solving the problem. -->\n![image.png](https://assets.leetcode.com/users/images/0018a7db-ad2d-4be0-ac32-7ca72c6e4501_1673665384.0892494.png)\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n    public String smallestEquivalentString(String s1, String s2, String base) {\n        int A[] = IntStream.range(0,26).toArray();\n        for(int i=0;i<s1.length();i++){\n            int p1=find(s1.charAt(i)-\'a\',A),p2=find(s2.charAt(i)-\'a\',A);\n            if(p1<p2)A[p2]=p1;\n            else A[p1]=p2;\n        }\n        return base.chars().mapToObj(c->String.valueOf((char)(\'a\'+find(c-\'a\',A)))).collect(Collectors.joining());\n    }    \n```\n```\nprivate int find(int id,int[] A){\n        while(A[id]!=id) id=A[id];\n        return id;\n    }\n```\n```\n public String smallestEquivalentString(String s1, String s2, String base) {\n        int A[] = new int[26];\n        for(int i=0;i<26;i++)A[i]=i;\n        for(int i=0;i<s1.length();i++){\n            int p1=find(s1.charAt(i)-\'a\',A),p2=find(s2.charAt(i)-\'a\',A);\n            if(p1<p2)A[p2]=p1;\n            else A[p1]=p2;\n        } StringBuilder sb= new StringBuilder();\n        for(var c:base.toCharArray()) sb.append((char)(\'a\'+find(c-\'a\',A)));\n        return sb.toString();\n    }
['Python', 'C++', 'Java', 'Python3']