C# - Started as Brute-Force, now beats 100% runtime and 100% memory efficiency :)
Intuition\n Describe your first thoughts on how to solve this problem. \n\nThe first realization towards solving this problem is that if b is even, the even-odd
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe first realization towards solving this problem is that if b is even, the even-odd parity of indexes will not be able to change. In other words, when b is even the odd indexes will always be odd and the even indexes will always be even.\n\nIf b is odd, then all numbers have opportunity to be at odd indices.\n\nThe next realization came with thinking about what happens when we add \'a\' to a character, and it overflows over 9 and back starting at 0. This is effectively a modulo 10 operation. Thinking in these terms, the maximum amount of times we would ever want to add \'a\' to the chars by would be 9. This is because at 10, the shift would be equivelent to adding \'a\' * 10 onto the char. and because we\'re modulo\'ing by 10, that is equivelent to shifting the char by \'a\' * 0, meaning we\'re back at the place where we began.\n\nFinally the last realization was that we don\'t even need to add \'a\' 9 times - instead we need to have an index start at 0, and keep adding \'a\' while moduling by 10 until that index ends up back at 0 - often this will take several steps less than 9 which in the grand scheme of things saves some decent time.\n\nWe can actually use this same principle for checking the points to rotate the string by. Start the rotation at 0 and continue adding \'b\' to the rotation point, while modulo\'ing it by the length of the string. Keep doing this until the index reaches 0 again.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$Fast !$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\nThis ran at 63 MS - the fastest runtime on the charts was 121 MS\n\n- Space complexity: $$Wow- strings$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nTook 73 MB - the best memory solution on the charts took 111 MB.\n\n\n# Edit - \nNow it is running at 140 MS and 40 MB of memory - thanks LeetCode! The solution that clocked at 121 MS runs currently at 223 MS so I guess I can still feel good about this runtime.\n\n# Code\n```\npublic class Solution {\n    public string FindLexSmallestString(string s, int a, int b) {\n        if (b % 2 == 0){\n            StringBuilder sb = new();\n            string min = ".";\n\n            int shift = 0;\n            int timesShift = 0;\n            while (shift != 0 || timesShift == 0){\n\n                sb.Clear();\n                for (int ind = 0; ind < s.Length; ind++){\n                    if (ind % 2 == 0) sb.Append(s[ind]);\n                    else{\n                        char c = (char)(((s[ind] - \'0\' + shift) % 10) + \'0\');\n                        sb.Append(c);\n                    }\n                }\n\n                string minSoFar = sb.ToString();\n                string sbStr = minSoFar;\n\n                int x = b;\n\n                while (x != 0){\n                    sb.Clear();\n                    sb.Append(sbStr[x..]).Append(sbStr[0..x]);\n\n                    if (minSoFar.CompareTo(sb.ToString()) == 1){\n                        minSoFar = sb.ToString();\n                    }\n                    x += b;\n                    x %= s.Length;\n                }\n\n                if (min == "." || min.CompareTo(minSoFar) == 1){\n                    min = minSoFar;\n                }\n\n                timesShift++;\n                shift += a;\n                shift %= 10;\n            }\n\n            return min;\n        }\n        else{\n            StringBuilder sb = new();\n            string min = ".";\n            int shiftOdd = 0;\n            int shiftEven = 0;\n            int timesOdd = 0;\n            int timesEven = 0;\n            while (shiftOdd != 0 || timesOdd == 0){\n                timesEven = 0;\n                while (shiftEven != 0 || timesEven == 0){\n\n                    sb.Clear();\n                    for (int ind = 0; ind < s.Length; ind++){\n                        if (ind % 2 == 0){\n                            char c = (char)(((s[ind] - \'0\' + shiftEven) % 10) + \'0\');\n                            sb.Append(c);\n                        }\n                        else{\n                            char c = (char)(((s[ind] - \'0\' + shiftOdd) % 10) + \'0\');\n                            sb.Append(c);\n                        }\n                    }\n\n                    string minSoFar = sb.ToString();\n                    string sbStr = minSoFar;\n\n                    int x = b;\n\n                    while (x != 0){\n                        sb.Clear();\n                        sb.Append(sbStr[x..]).Append(sbStr[0..x]);\n\n                        if (minSoFar.CompareTo(sb.ToString()) == 1){\n                            minSoFar = sb.ToString();\n                        }\n\n                        x += b;\n                        x %= s.Length;\n                    }\n\n                    if (min == "." || min.CompareTo(minSoFar) == 1){\n                        min = minSoFar;\n                    }\n                    shiftEven += a;\n                    shiftEven %= 10;\n                    timesEven++;\n                }\n\n                shiftOdd += a;\n                shiftOdd %= 10;\n                timesOdd++;\n            }\n            return min;\n        }\n    }\n}\n```
['Math', 'String', 'C#']