Pattern Recognition Drill
Medium Dynamic Programming
The Problem
Count ways to decode a digit string into letters (A=1, B=2, ..., Z=26).
What approach would you use?
Think about it before scrolling down.
dp[i] = dp[i-1] if valid single digit + dp[i-2] if valid two digits. O(n) time.
Common Trap
'0' is not a valid single digit — handle it. '06' is not a valid two-digit code. Edge cases matter.