Splitting a String Into Descending Consecutive Values

Medium Topics Company Tags

Split the digit string s into at least two nonempty, contiguous parts that together use every character. Interpret each part as a non-negative decimal integer; leading zeros are allowed. Return true if every value is exactly one less than the preceding value, and false if no such split exists.

Example 1:

Input: s = "3210"

Output: true

Explanation: Split into 3, 2, 1, and 0. Each value is exactly one smaller than the previous value.

Example 2:

Input: s = "00100"

Output: true

Explanation: The split 001 | 00 has values 1 and 0. Leading zeros are allowed, and the difference is exactly one.

Example 3:

Input: s = "00"

Output: false

Explanation: The only split is 0 | 0. Equal adjacent values do not differ by one, so the answer is false.

Constraints:

  • 1 <= s.length <= 20
  • s contains only decimal digits.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.