Restore The Array

A program was supposed to print an array of integers. The program forgot to print whitespaces, so the array is printed as a string of digits s. All we know is that every integer in the array was in the range [1, k] and there are no leading zeros in the array.

Given the string s and the integer k, return the number of possible arrays that could have been printed as s using the mentioned program. Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputs = "1000", k = 10000
Output1
The only possible array is [1000].
Example 2
Inputs = "1000", k = 10
Output0
There cannot be an array that was printed this way and has all integers >= 1 and <= 10.

Constraints

  • 1 <= s.length <= 10^5
  • s consists of only digits and does not contain leading zeros.
  • 1 <= k <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate