Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Python Code to Count Possible Decoding Of A Given Digit Sequence
Count Possible Decoding Of A Given Digit Sequence
Python Code to Count Possible Decoding of a Given Digit Sequence returns the number of decodings possible for a string. Here decodings must be a valid English alphabet. Check below example for better understanding
- String=”127″ , possible decodings are
In the above example 27 is not a valid decoding as highest number possible is 26 which is “z”.
- Step 1: Start
- Step 2: User is required to insert a digit sequence as an input
- Step 3: Set count = 0
- Step 4: If the last number is not a zero, then return for the next remaining (n-1) numbers and add the results then to the total count.
- Step 5: If the last two digits form a valid variable (or smaller than 27), return for the remaining (n-2) numbers and add the outcome to the total calculation.
- Step 6: Stop