Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Decode Ways

Medium
dynamic-programmingstring

Letters map to digits A=1 … Z=26. Given a digit string s, count how many ways it can be decoded (e.g. "12" → "AB" or "L"). Leading zeros in a group are invalid.

Input: one line, the digit string. Output: the number of decodings (0 if none).

Example 1
Input:
12
Output:
2
Example 2
Input:
226
Output:
3

2|26, 22|6, 2|2|6.

Example 3
Input:
06
Output:
0

Constraints

  • 1 ≤ s.length ≤ 100
  • Digits only; may contain zeros.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.