ORIGINAL CODING QUESTION
Digit message decoding count
A=1 through Z=26. Count ways to decode the full digit sequence. Zero cannot stand alone; a pair may not begin with zero. Return the count modulo 1,000,000,007.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n integer values. Print one integer as described.
Constraints
1 ≤ n ≤ 30; each token is one decimal digit in [0,9].
Example 1
Input
3 2 2 6
Output
3
Decode as 2|2|6, 22|6 or 2|26.
Example 2
Input
2 0 6
Output
0
A leading zero prevents decoding.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
A prefix can end with a valid one-digit or two-digit letter.
Hint 2
A zero must be part of 10 or 20.
Hint 3
Add the counts for valid final choices.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →