Ctrl K

Letter and Step Code

Easy
To save space, a word is stored in a compact form: even positions (0-indexed) hold lowercase English letters and odd positions hold digits. A digit d at position i stands for the letter that comes d places after code[i - 1] in the alphabet. For example, c followed by 4 means g, and the digit 0 repeats the previous letter. Given the compact string code, replace every digit with the letter it stands for and return the resulting word. The shift is guaranteed never to go past z.
Example 1
code='m2p0' → 'mopp'

The 2 after "m" becomes "o" (two letters further), and the 0 after "p" becomes "p" itself.

Example 2
code='a3t5w' → 'adtyw'

"a" + 3 = "d", "t" + 5 = "y", and the final "w" sits at an even position and stays as is.

Constraints
  • 1 ≤ code.length ≤ 100
  • even positions of code hold lowercase English letters, odd positions hold digits
  • for every odd position i, the letter code[i - 1] shifted by code[i] is not past z
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
code='m2p0'
Expected
'mopp'

Run checks the first 3 tests in your browser. Submit checks all 40 tests on the server, hidden ones included.