Skip to content

Practice Restore The Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1416
LeetCode Problem

Restore The Array

Problem Statement

A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array were 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 the possible arrays that can be printed as s using the mentioned program. Since the answer may be very large, return it modulo 10^9 + 7.

Source: Restore The Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "1000", k = 10000
Output
1

# Example 2

Input
s = "1000", k = 10
Output
0

# Example 3

Input
s = "1317", k = 2000
Output
8

Constraints

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

Related LeetCode Problems

Practice more problems similar to Restore The Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.