digits of even length. You may apply two moves any number of times, in any order:
- **Add:** add step to every digit at an odd position (0-indexed); digits wrap around from 9 back to 0. For example, with step = 5, 3456 becomes 3951.
- **Rotate:** rotate the string to the right by shift positions. For example, with shift = 1, 3456 becomes 6345.
Return the lexicographically smallest string you can reach with these moves (the original string counts, if you do nothing).digits="1938", step=1, shift=2 → '1039'
Rotating by 2 only gives 1938 and 3819, and odd positions 1 and 3 turn together. For 1938, adding 1 once gives 1039; every variant of 3819 starts with 3, which is worse. The answer is 1039.
digits="95", step=5, shift=1 → '04'
95 → add: 90 → rotate: 09 → add: 04. Nothing smaller is reachable: the first digit is always 0 or 5, the second always 4 or 9.
digits="000000", step=3, shift=4 → '000000'
len(digits) is evendigits consists of digits 0 to 9digits="1938", step=1, shift=2
'1039'
Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.