Intuition
Pretty straightforward, have a mutable form of the string like a list (or create new string and append to it). Then when you encounter a digit, calculate character for that index using the previous character and current digit.
Hint: for Python devs, use
ord()
to get ASCII value of a character andchr()
to convert a digit into a character.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we would be visiting all characters in the string of length N.
-
Memory
The memory usage is since we convert the input string into a list
v
.
— A