Blind 75
Decode Ways (medium)
Problem Statement
You have given a string that consists only of digits. This string can be decoded into a set of alphabets where '1' can be represented as 'A', '2' as 'B', ... , '26' as 'Z'. The task is to determine how many ways the given digit string can be decoded into alphabets.
Examples
-
- Input: "121"
- Expected Output: 3
- Justification: The string "121" can be decoded as "ABA", "AU", and "LA".
-
- Input: "27"
- Expected Output: 1
- Justification: The string "27" can only be decoded as "BG".
-
- Input: "110"
- Expected Output: 1
- Justification: The string "110" can only be decoded as "JA".
Constraints:
1 <= s.length <= 100
s
contains only digits and may contain leading zero(s).
Try it yourself
Try solving this question here:
Python3
Python3