JAVA | DFS | Simulation
Do upvote if you like the solution, and comment if optimizations of the approach are possible.\n\n\nclass Solution {\n    private String result;\n    public Str
Do upvote if you like the solution, and comment if optimizations of the approach are possible.\n\n```\nclass Solution {\n    private String result;\n    public String findLexSmallestString(String s, int a, int b) {\n        result = "z";\n        HashSet<String> set = new HashSet<>();\n        dfs(s, a, b, set);\n        return result;\n    }\n    private void dfs(String s, int a, int b, HashSet<String> set) {\n        if(set.contains(s))\n            return;\n        set.add(s);\n        String s1, s2;\n        s1 = addA(s, a);\n        s2 = rotateB(s, b);\n        dfs(s1, a , b, set);\n        dfs(s2, a , b, set);\n    }\n    private String addA(String s, int a) {\n        char c[] = s.toCharArray();\n        int i, temp;\n        for(i=1;i<s.length();i+=2) {\n            temp = c[i] - \'0\';\n            temp += a;\n            temp = temp % 10;\n            c[i] = (char)(temp + \'0\');\n        } \n        s = new String(c);\n        if(result.compareTo(s) > 0)\n            result = s;\n        return s;\n    }\n    private String rotateB(String s, int b) {\n        if(b < 0)\n            b += s.length();\n        b = b % s.length();\n        b = s.length() - b;\n        s = s.substring(b) + s.substring(0, b);\n        if(result.compareTo(s) > 0)\n            result = s;\n        return s;\n    }\n}\n```\n\nThank You!
['Depth-First Search', 'Simulation', 'Java']