Practice Decode Ways
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Decode a digit string using the integer codes 1 through 26 for letters A through Z. Count all valid ways to split the entire string into such codes. A code cannot start with zero: 0 alone and 06 are invalid, while 10 and 20 are valid. Return zero when no full decoding exists. The answer fits in a signed 32-bit integer. Practice approach: Use dynamic programming over prefixes. A nonzero final digit can extend each decoding of the previous prefix; a final pair from 10 through 26 can extend each decoding from two positions earlier. Add the applicable counts. Keep only the last two counts for O(1) extra space and O(n) time.
Source: Decode Ways on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "12"
2
# Example 2
s = "226"
3
# Example 3
s = "06"
0
Constraints
Related LeetCode Problems
Practice more problems similar to Decode Ways.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.