Your task is to modify a given string as follows:
- Find the first position in the string that has two consecutive occurrences of the same character.
- If there is no such position, exit.
- Remove the two characters and replace them with a single character that is the next character in the alphabetical order. However, if the removed character is
z
, then the replacing character isa
. - Return to step 1.
The string consists of the characters a
-z
and contains at most 10^5 characters.
In a file chars.py
implement a function solve
that returns the modified string.
def solve(s): # TODO if __name__ == "__main__": print(solve("auto")) # auto print(solve("ddqqirr")) # eris print(solve("aaaaaa")) # cb print(solve("wsstuva")) # xa print(solve("zzzzzzzz")) # c print(solve("mlkjihgfedcbb")) # n print(solve("kkkjjiikjkjiikjjiijkjji")) # mjkjmlki
Explanation: For example, the string aaaaaa
is modified as follows: aaaaaa
\rightarrow baaaa
\rightarrow bbaa
\rightarrow caa
\rightarrow cb