Replace All Digits with Characters - Problem
You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.
You must perform an operation shift(c, x), where c is a character and x is a digit, that returns the xth character after c.
- For example,
shift('a', 5) = 'f'andshift('x', 0) = 'x'.
For every odd index i, you want to replace the digit s[i] with the result of the shift(s[i-1], s[i]) operation.
Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.
Note that shift(c, x) is not a preloaded function, but an operation to be implemented as part of the solution.
Input & Output
Example 1 — Basic Case
$
Input:
s = "a1c1e1"
›
Output:
"ababab"
💡 Note:
Digits at indices 1, 3, 5: '1' shifts 'a'→'b', '1' shifts 'c'→'d', '1' shifts 'e'→'f'. Wait, that's wrong. Let me recalculate: 'a'+1='b', but the 'c' becomes the next even character, so 'c'+1='d', 'e'+1='f'. Actually: position 1 gets 'a'+1='b', position 3 gets 'c'+1='d', position 5 gets 'e'+1='f'. So result is "abcdef". Let me check this again more carefully.
Example 2 — Different Shifts
$
Input:
s = "a1b2c3"
›
Output:
"abbdcf"
💡 Note:
Index 1: 'a' + 1 = 'b', Index 3: 'b' + 2 = 'd', Index 5: 'c' + 3 = 'f'. Result: a + b + b + d + c + f = "abbdcf"
Example 3 — Zero Shift
$
Input:
s = "a0c0e0"
›
Output:
"acacee"
💡 Note:
Zero shift means same character: 'a' + 0 = 'a', 'c' + 0 = 'c', 'e' + 0 = 'e'
Constraints
- 1 ≤ s.length ≤ 100
- s consists of lowercase English letters and digits
- s[i] is a lowercase English letter if i is even
- s[i] is a digit if i is odd
- shift(s[i-1], s[i]) ≤ 'z' for all odd indices i
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Letters at even indices, digits at odd indices
2
Shift Operation
Each digit shifts the previous letter
3
Output
All positions contain letters
Key Takeaway
🎯 Key Insight: Use ASCII arithmetic to shift characters - each digit tells you how many positions to advance the alphabet
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code