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 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!
Select
Add answer anonymously...

Daffodil Software Software Developer interview questions & answers

A Software Developer was asked Q. What are your qualifications?
A Software Developer was asked Q. Given an array of numbers, find the largest prime number in the array using the ...read more
A Software Developer was asked Q. Write a program to print the pattern.

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. What are your hobbies?
A Software Developer was asked Q2. What are your qualifications?
A Software Developer was asked Q3. Given an array of numbers, find the largest prime number in the array using the ...read more
Daffodil Software Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits