Skip to the code
cf.
+25 XP

#485 Count Icon Code Readings

medium

An icon font numbers its icons from 1 to 26. A sharing link stores a list of icons by writing their numbers one after another with nothing in between, so the list (1, 12) and the list (11, 2) both become "112".

Write countIconReadings(code) that returns how many different icon lists could have produced code. Each piece must be a number from 1 to 26 written without a leading zero, so "06" is not a valid piece and neither is "0". If no reading exists, return 0.

The count can be very large, so return it modulo 1000000007.

Example 1

Input: code = "15"
Output: 2

Icons (1, 5) or icon (15).

Example 2

Input: code = "125"
Output: 3

(1, 2, 5), (12, 5), or (1, 25).

Constraints

  • 1 <= code.length <= 1000
  • code contains only the digits 0 to 9.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).