A message of digits can be decoded where '1'→A, '2'→B, ..., '26'→Z. Given a digit string, count the number of ways to decode it.
dp[i] = ways to decode s[:i]. If s[i-1] != '0', dp[i] += dp[i-1]. If s[i-2:i] is 10-26, dp[i] += dp[i-2].
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
numDecodings('226')
3
numDecodings('12')
2