Decode Ways
A message of digits is encoded with the mapping 'A'->1, 'B'->2, ..., 'Z'->26. Given a non-empty string s of digits, count how many distinct ways it can be decoded back into letters. A leading zero or an invalid pair (0X, or a two-digit value above 26) blocks that path.
Open official problem prompt ↗Count every valid way to break the digit string into chunks of size 1 or 2 that each map to a letter A-Z.
Like climbing stairs where you may take 1 or 2 steps, except some steps are boarded up (a '0' or a pair above 26 removes that move).
- Input
- s = "226"
- Output
- 3
- Why
- "226" splits as (2 2 6)->BBF, (22 6)->VF, (2 26)->BZ.
1 <= s.length <= 100s contains only digits and may contain leading zeros