FunctionRacerProblemsRace

Letter Decodings

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

A message was written down by replacing each letter with its number: A became 1, B became 2, and so on up to Z, which became 26. The numbers were written one after another with nothing in between, giving the string digits. Return how many different letter strings the message could have been. A 0 can only be the second digit of 10 or 20; a group such as 06 is not a letter. If no reading is possible, return 0.

Example 1

digits "226"
returns 3

The readings are 2-26 (BZ), 22-6 (VF) and 2-2-6 (BBF).

Example 2

digits "1201"
returns 1

The 0 must belong to 20, which forces the single reading 1-20-1 (ATA).

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems