Decode Ways — C# Coding Problem
Difficulty: medium | Category: dynamic-programming
Problem Description
A message containing letters from `A-Z` is encoded as numbers using `A=1, B=2, ..., Z=26`. Given a string `s` containing only digits, return the **number of ways** to decode it. **Constraints:** - `1 <= s.length <= 100` - `s` contains only digits, and may contain leading zeros. **Examples:** - `"12"` → `2` (decoded as `"AB"` or `"L"`) - `"226"` → `3` (`"BZ"`, `"VF"`, or `"BBF"`) - `"06"` → `0` (leading zero with no valid mapping)
Examples
Example 1
Input: s = "12"
Output: 2
Explanation: "AB" (1,2) or "L" (12)
Example 2
Input: s = "226"
Output: 3
Example 3
Input: s = "06"
Output: 0