Problem 547462 · medium · Level 05 Advanced Algorithms & Graphs

Split Digits Into Rising Numbers

backtracking · strings · counting · partitioning

A receipt printer merged a sequence of numbers into one digit string digits. The original sequence was strictly increasing, and no number was written with a leading zero (the number 0 itself is written "0"). Count how many ways digits can be split into one or more pieces that form such a sequence. Keeping the whole string as a single number counts as one way (if it has no leading zero).

Examples

Input:  digits = "1234"
Output: 5
Explanation: 1234 | 1,234 | 12,34 | 1,2,34 | 1,2,3,4.

Input:  digits = "321"
Output: 2
Explanation: 321 | 3,21.

Input:  digits = "10"
Output: 1
Explanation: 1,0 is not increasing.

Constraints

  • 1 <= len(digits) <= 16, digits only

Goals

  • Partition a string while carrying the previous piece as state
  • Reject pieces with leading zeros
Starting Python…