Java 30 lines 3ms Greedy beat 100%
\nclass Solution {\n    public String findLexSmallestString(String s, int a, int b) {\n        String res = s;\n        int i=0, n=s.length();\n        Set<Stri
```\nclass Solution {\n    public String findLexSmallestString(String s, int a, int b) {\n        String res = s;\n        int i=0, n=s.length();\n        Set<String> seen = new HashSet<>();\n        while (seen.add(s)){\n            i=(i+b)%n;\n            char[] ca = s.toCharArray();\n            if (b%2==1) update(ca, a, 0);\n            update(ca, a, 1);\n            String temp = new String(ca);\n            if (res.compareTo(temp)>0) res = temp;\n            s = s.substring(b)+s.substring(0,b);\n        }\n        return res;\n    }\n    \n    void update(char[] ca, int a, int o){\n        int times = 0, cur = ca[o]-\'0\', min = ca[o], t=0;\n        Set<Integer> seen = new HashSet<>();\n        while (seen.add(cur)){\n            if (cur<min){\n                min=cur;\n                times = t; \n            }\n            cur=(cur+a)%10;\n            t++;\n        }\n        for (int i=o; i<ca.length; i+=2){\n            ca[i]=(char)((ca[i]-\'0\'+times*a)%10+\'0\');\n        }\n    }\n}\n```
[]