java solution using dfs✅
\nclass Solution {\n    \n    public String smallestEquivalentString(String s1, String s2, String baseStr) {\n        int m = s1.length();\n        int n = base
```\nclass Solution {\n    \n    public String smallestEquivalentString(String s1, String s2, String baseStr) {\n        int m = s1.length();\n        int n = baseStr.length();\n        \n        ArrayList<Character>[] graph = new ArrayList[26];\n        \n        for (int i = 0 ; i < 26 ; i++) {\n            graph[i] = new ArrayList<Character>();\n        }\n        \n        for (int i = 0 ; i < m ; i++) {\n            char u = s1.charAt(i);\n            char v = s2.charAt(i);\n            \n            graph[u - \'a\'].add(v);\n            graph[v - \'a\'].add(u);\n        }\n        \n        StringBuilder result = new StringBuilder();\n        \n        for (int i = 0 ; i < n ; i++) {\n            char currentBaseStrCharacter = baseStr.charAt(i);\n            \n            boolean[] visited = new boolean[26];\n            \n            char ch = DFS(graph, visited, currentBaseStrCharacter);\n           \n            result.append(ch);\n        }\n        \n        return result.toString();\n    }\n    \n    public char DFS(ArrayList<Character>[] graph, boolean[] visited, char currentCharacter) {\n        visited[currentCharacter - \'a\'] = true;\n        \n        char curr_ch = currentCharacter;\n        \n        for (char v : graph[currentCharacter - \'a\']) {\n            if (!visited[v - \'a\']) {\n                char min = DFS(graph, visited, v);\n                \n                if (min < curr_ch) {\n                    curr_ch = min;\n                }\n                \n            }    \n        }\n        \n        return curr_ch;\n    }\n    \n}\n```\nUpvote if you like it![image](https://assets.leetcode.com/users/images/94c985bf-b250-41a3-80a8-98aa250e057a_1673733698.996035.png)\n
['Depth-First Search', 'Java']