JAVA 4ms 100% | O(N^2/(GCD(N,b))) time | with full comments.
\nclass Solution {\n    public String findLexSmallestString(String ss, int a, int b) {\n        \n        StringBuilder temp = new StringBuilder(ss);\n        S
```\nclass Solution {\n    public String findLexSmallestString(String ss, int a, int b) {\n        \n        StringBuilder temp = new StringBuilder(ss);\n        StringBuilder ans = temp;\n        int n = ss.length();\n        \n        do{\n            \n            StringBuilder s = new StringBuilder(temp);\n\t\t\t\n            // extract the int value from index 1\n            int x = (int)(s.charAt(1)-\'0\');\n            int whichMultiple = 0;\n            int zz = x;\n\t\t\t\n            // find out which multiple of \'a\' should be added to the index1 so that it becomes minimum\n\t\t\t// here \'whichMultiple\' variable represent that value (i\'th multiple of  \'a\')\n            for(int i=0;i<10;i++){\n                int z = ((i*a)+x)%10;\n                if(z<zz){\n                    zz = z;\n                    whichMultiple = i;\n                }\n            }\n            \n\t\t\t// then add that multiple of \'a\' to all odd index values and take the last digit as we have to cycle back to 0 after crossing 9\n            for(int i=0;i<n;i++){\n                if(i%2==1){\n                    s.setCharAt(i,(char)((((whichMultiple*a)+(s.charAt(i)-\'0\'))%10)+\'0\'));\n                }\n            }\n            \n\t\t\t// Repeat the above process for even index values if b is odd\n            if(b%2==1){\n                int y = s.charAt(0)-\'0\';\n                int whichMultiple2 = 0;\n                int ww = y;\n                for(int i=0;i<10;i++){\n                    int z = ((i*a)+y)%10;\n                    if(z<ww){\n                        ww = z;\n                        whichMultiple2 = i;\n                    }\n                }\n                for(int i=0;i<n;i++){\n                    if(i%2==0){\n                        s.setCharAt(i,(char)((((whichMultiple2*a)+(s.charAt(i)-\'0\'))%10)+\'0\'));\n                    }\n                } \n            }\n            \n\t\t\t// finally compare the modified string( variable \'s\') to the \'ans\' string which stores smallest string found till now\n\t\t\t// update the \'ans\' if currently modified string( variable \'s\') is smaller than it.\n            if(ans.compareTo(s)>0){\n                ans = s;\n            }\n            \n\t\t\t\n\t\t\t// rotate the original string \'b\' times to the right\n            temp.insert(0,temp.substring(n-b,n)); // take last \'b\' characters and append them to the head(starting od string)\n            temp.delete(n,n+b); // delete those last \'b\' characters\n            \n        }while(!temp.toString().equals(ss)); // continue this process until the the \'temp\' string becomes equal to the input string( variable \'ss\') \n\t\t// which indicates that we have iterated through all possible different strings (which will be n/gcd(n,b), here n is size of input string)\n        \n        return ans.toString();\n    }\n}\n```
['String', 'Depth-First Search', 'Simulation', 'Enumeration', 'Java']