Decode Ways
Signals to notice
Brute force first
Recursively try decoding one or two digits at each position. Many substrings are re-decoded across different branches. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
The key insight
DP: dp[i] = (ways using single digit) + (ways using two digits). If s[i] is valid (1-9), add dp[i-1]. If s[i-1.i] forms 10-26, add dp[i-2]. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
What must stay true
At each position, you either decode one character or two. The total decodings is the sum of both valid choices. dp[i] depends only on dp[i-1] and dp[i-2]. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Easy way to go wrong
Forgetting that '0' cannot be decoded alone — if s[i] = '0', there are zero ways from single-digit decoding. Also, leading zeros in two-digit codes (like '06') are invalid. The fix is usually to return to the meaning of each move, not just the steps themselves.