← Dynamic Programming

Pattern Recognition Drill

#70 — Decode ways

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.

Key Signals

Dynamic Programming

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.

← #69 #71 →