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
4mo
The task is to determine the number of possible ways to decode a given sequence of digits back into a string of characters from 'A' to 'Z'.
Use dynamic programming to solve the problem efficiently.
Cons...read more
Help your peers!
Add answer anonymously...
Goldman Sachs Analyst interview questions & answers
An Analyst was asked 10mo agoQ. What is a strength of yours?
An Analyst was asked Q. How do you merge multiple sorted arrays into one sorted array?
An Analyst was asked Q. Explain what a Binary Search Tree is.
Popular interview questions of Analyst
An Analyst was asked Q1. How do you merge multiple sorted arrays into one sorted array?
An Analyst was asked Q2. Explain what a Binary Search Tree is.
An Analyst was asked Q3. Given a matrix where each row and each column is sorted in ascending order, how ...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

