Number of Ways to Separate Numbers

You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros.

Return the number of possible lists of integers that you could have written down to get the string num. Since the answer may be large, return it modulo 10^9 + 7.

Example 1
Inputnum = "327"
Output2
You could have written down the numbers 3, 27 or 327.
Example 2
Inputnum = "094"
Output0
No numbers can have leading zeros and all numbers must be positive.

Constraints

  • 1 <= num.length <= 3500
  • num consists of digits '0' through '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