Lexicographically Smallest String After Applying Operations
You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.
You can apply either of the following two operations any number of times and in any order on s:
- Add
ato all odd indices ofs(0-indexed). Digits past9are cycled back to0. - Rotate
sto the right bybpositions.
Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.
A string a is lexicographically smaller than a string b of the same length if, in the first position where a and b differ, string a has a character that appears earlier in the alphabet than the corresponding character in b.
Example 1
Input
s = "5525", a = 9, b = 2Output
"2050"After applying a sequence of rotations and additions, the smallest obtainable string is "2050".
Example 2
Input
s = "74", a = 5, b = 1Output
"24"After rotating and adding as shown, the smallest obtainable string is "24".
Constraints
- 2 <= s.length <= 100
- s.length is even.
- s consists of digits from 0 to 9 only.
- 1 <= a <= 9
- 1 <= b <= s.length - 1