Requirements
- Input: receive a nonempty string
s made up of digits.
- Letter conversion:
"1" → A, "2" → B, …, "26" → Z.
- Output: return how many different valid letter decodings can be formed from
s.
- Constraints: a zero at the beginning or a zero that cannot pair with its preceding digit makes that path invalid (for example,
"04" and "30" cannot be decoded); a two-character number may be used only when it falls from 10 through 26, inclusive.
public static int decode_ways(String s)
Notes
- Important boundary cases that may be absent from visible tests:
"0" must produce 0; "20" and "10" each produce 1; "28" produces 1 because only separate single-digit letters are allowed.
- This is the standard Decode Ways task. A related version permits a
* wildcard, but that extension is not part of this problem.
Preparation
- Before submission, manually practice cases involving an initial zero and a zero that appears by itself.
- Practice the standard Decode Ways exercise; for an additional challenge, try the variant that includes the
* wildcard.