Replace All Digits with Characters

easy string simulation

Problem

You are given a string s of even-indexed lowercase letters and odd-indexed digits. For every odd index i, replace the digit s[i] with the letter you get by shifting the previous character s[i-1] forward by s[i] positions in the alphabet. Even-indexed letters stay as they are. Return the resulting string.

Inputs = "a1c1e1"
Output"abcdef"
shift('a',1)='b', shift('c',1)='d', shift('e',1)='f'.

def replace_digits(s):
    res = list(s)
    for i in range(1, len(s), 2):
        prev = res[i - 1]
        shift = int(s[i])
        res[i] = chr(ord(prev) + shift)
    return "".join(res)
function replaceDigits(s) {
  const res = s.split("");
  for (let i = 1; i < s.length; i += 2) {
    const prev = res[i - 1].charCodeAt(0);
    const shift = s.charCodeAt(i) - 48;
    res[i] = String.fromCharCode(prev + shift);
  }
  return res.join("");
}
class Solution {
    public String replaceDigits(String s) {
        char[] res = s.toCharArray();
        for (int i = 1; i < res.length; i += 2) {
            int shift = res[i] - '0';
            res[i] = (char) (res[i - 1] + shift);
        }
        return new String(res);
    }
}
string replaceDigits(string s) {
    for (int i = 1; i < (int)s.size(); i += 2) {
        int shift = s[i] - '0';
        s[i] = s[i - 1] + shift;
    }
    return s;
}
Time: O(n) Space: O(n)