Digits Decoding Problem
Ninja has a string of characters from 'A' to 'Z', encoded using their numeric values (A=1, B=2, ..., Z=26). The encoded string is given as a sequence of digits (SEQ). The task is to determine the number of possible ways to decode this sequence back into a string consisting only of characters from 'A' to 'Z'.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first and only line of each test case contains a digit sequence.
Output:
For each test case, print the number of ways to decode the given digit sequence in a separate line.
Example:
Input:
1
121
Output:
3
Explanation:
The sequence 121 can be decoded as:
1. 1 = A, 2 = B, 1 = A so ABA
2. 12 = L, 1 = A so LA
3. 1 = A, 21 = U so AU
Thus, there are 3 ways: [ABA, LA, AU].
Constraints:
- 1 <= T <= 10
- 1 <= N <= 105
- 0 <= SEQ[i] <= 9
- Time limit: 1 sec
Note:
The input sequence will always have at least 1 possible way to decode.
The answer should be returned modulo 10^9 + 7.
Space optimization is encouraged for solving.
AnswerBot
3d
The task is to determine the number of possible ways to decode a sequence of digits back into a string of characters from 'A' to 'Z'.
Use dynamic programming to keep track of the number of ways to deco...read more
Help your peers!
Add answer anonymously...
Top Daffodil Software Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Daffodil Software Software Developer
>
Daffodil Software Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app