Simple BFS | Java |
Approach\n Describe your approach to solving the problem. \n    Try All possiblities and take the minimum String.\n\n\n\nclass Solution {\n    public String add
# Approach\n<!-- Describe your approach to solving the problem. -->\n    Try All possiblities and take the minimum String.\n\n\n```\nclass Solution {\n    public String addNumber(String s, int a, int n) {\n        char[] c = s.toCharArray();\n\n        for(int i=1; i<n; i+=2) {\n            c[i] = (char)(\'0\' + ((c[i]-\'0\')+a)%10);\n        }\n        return String.valueOf(c);\n    }\n\n    public String findLexSmallestString(String s, int a, int b) {\n        Set<String> taken = new HashSet<>();\n        Queue<String> queue = new LinkedList<>();\n        queue.add(s);\n        taken.add(s);\n\n        int n = s.length();\n        String res = s;\n        while(queue.size() > 0) {\n            String curr = queue.remove();            \n\n            res = (curr.compareTo(res) < 0) ? curr : res;\n\n            String rotate = curr.substring(n-b) + curr.substring(0, n-b);\n            String add = addNumber(curr, a, n);\n\n            if(taken.add(rotate)) {\n                queue.add(rotate);\n            }\n\n            if(taken.add(add)) {\n                queue.add(add);\n            }\n        }\n        return res;\n    }\n}\n```
['Java']