A is 1, B is 2, …, Z is 26. A message was written as one unbroken string of digits, so it can often be read in several ways: 126, for instance, is ABF, LF or AZ. A number with a leading zero (05) is not a letter, and neither is a lone 0.
Some digits have worn off and show as *; each one could be any digit from 1 to 9 (never 0). Different choices for the stars give different messages, and all their readings count.
Given code, a string of digits and stars, return the total number of ways to read it as text. The answer can be huge, so return it modulo 10⁹ + 7.code="3*" → 9
* becomes any digit from 1 to 9. Each variant can be read digit by digit (9 ways), and none of 31…39 is a letter, since they exceed 26. Total: 9.
code="*0" → 2
A zero is not a letter on its own, so it must pair with the digit before it: only 10 and 20 work. The answer is 2.
code="12" → 2
1 2 reads as AB and 12 reads as L: two readings.
* characterscode="3*"
9
Run checks the first 3 tests in your browser. Submit checks all 160 tests on the server, hidden ones included.