Explore
Placement Prep

Edit

Edit

# Find the possible number of decodings of a given digit sequence | FACE Prep

Published on 11 Mar 2020

Program to find the possible number of decodings of a given digit sequence is discussed here. Given a digit sequence, find the number of possible decodings of the given digit sequence.

Let 'A' represent 1 ,'B' represent 2, and so on.

For example,

Input: digits[] = "123"

Output: 3

/* The possible decodings are "ABC", "LC", "AW" */

Input: digits[] = "121"

Output: 3

/* The possible decodings are "ABA", "AU", "LA" */

## Algorithm to find the possible number of decodings of a given digit sequence

• Input the digit sequence.
• Initialize count = 0.
• If the last digit is non-zero, recur for the next remaining (n-1) digits and then add the result to the total count.
• If the last two digits form a valid character (or smaller than 27), recur for the remaining (n-2) digits and add the result to total count.

## Program to find the possible number of decodings of a given digit sequence

C
C++
Java
Python 3

Output
Input - Enter the digit sequence : 1234 Output - Possible count of decoding of the sequence : 3

Recommended Programs