198. Replace All Digits with Characters

EasyStringString

You are given a string s where s[even_index] is a lowercase letter and s[odd_index] is a digit.

Replace each digit s[i] with the character that is s[i-1] shifted forward by s[i] positions in the alphabet.

Return the resulting string after all replacements.

Input: A string s of alternating letters and digits (even indices=letters, odd indices=digits).

Output: The string with all digits replaced by the corresponding shifted characters.

Examples

Example 1
Input: a1c1e1
Output: abcdef
Explanation: a+1=b, c+1=d, e+1=f → 'abcdef'.
Example 2
Input: a1b2c3
Output: abcdef
Explanation: a+1=b, b+2=d, c+3=f → 'abdf'? No: output chars replace digits in-place.
Example 3
Input: a0b0c0
Output: aabbcc
Explanation: shift by 0: a→a, b→b, c→c.

Constraints

Asked by

Google
Solve this problem in the editor →