Java | DFS
class Solution {\n \n    String ans="z";\n        public void dfs(String s,int a,int b,HashSet set)\n        {\n            if(set.contains(s))\n               
class Solution {\n \n    String ans="z";\n        public void dfs(String s,int a,int b,HashSet<String> set)\n        {\n            if(set.contains(s))\n                return;\n            set.add(s);\n            String one=add(s,a);\n            String two=rotate(s,b);\n           \n            dfs(one,a,b,set);\n            dfs(two,a,b,set);\n        }\n    \n    public String add(String s,int a)\n    {\n        char temp[]=s.toCharArray();\n        for(int i=1;i<temp.length;i=i+2)\n        {\n            int val=temp[i]-\'0\';\n            val=(val+a)%10;\n            temp[i]=(char) (val+\'0\');\n        }\n        \n        s=new String(temp);\n      if(ans.compareTo(s)>0)\n            ans=s;\n        \n        return s;\n    }\n    public String rotate(String s,int b)\n    {\n        if(b<0)\n            b=b+s.length();\n        b=b%s.length();\n        b=s.length()-b;\n        s=s.substring(b)+s.substring(0,b);\n        if(ans.compareTo(s)>0)\n            ans=s;\n        return s;\n    }\n \n    public String findLexSmallestString(String s, int a, int b) {\n        \n        HashSet<String> set=new HashSet<>();\n        dfs(s,a,b,set);\n        return ans;\n    }\n}
[]