Number of Ways to Decode Problem

Number of Ways to Decode Problem — ExecCode Medium DSA Practice

Solve the Number of Ways to Decode problem on ExecCode. Free online medium DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description Imagine you're solving Number of Ways to Decode in a real system where you must be correct and efficient. Problem Given a non-empty string of digits that represents an encoded message, determine the total number of ways to decode it. The encoding maps 'A'->"1", 'B'->"2", ..., 'Z'->"26". A valid decoding is obtained by partitioning the digit string into one- or two-digit numbers that each map to a letter (no leading zeros allowed in a number, and '0' cannot be decoded alone). Return the number of distinct decodings. Input Format A single line containing the digit string (no spaces). Output Format A single integer: the number of possible decodings. Constraints The input string contains only characters '0'–'9' and has length at least 1. You may assume the result fits in a 32-bit signed integer.

Examples

Input 12; Output 2. Input 226; Output 3

Constraints

1 <= s.length <= 100

Practice Number of Ways to Decode free on ExecCode. Browse DSA problems, topic map, and placement guides.