Check whether a digit string splits into consecutive increasing numbers

Quick Overview

Decide whether a string of digits can be cut into two or more pieces whose values go up by exactly one at each step, with no leading zeros allowed. It tests enumerating a starting choice, matching strings carefully, and handling edge cases such as a growing digit count and the number zero.

Check whether a digit string splits into consecutive increasing numbers

Company: Miro

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

You are given a string `s` of digits. Determine whether `s` can be split into a sequence of two or more non-empty substrings such that the numerical values of the substrings form a sequential combination, meaning each number is exactly one greater than the previous number. Leading zeros are not allowed in any substring (except for the number `0` itself, which must be the single character `"0"`). Return `True` if at least one valid split exists, otherwise return `False`. ### Function Signature ```python def split_into_sequential(s: str) -> bool: ``` ### Rules - The pieces must cover the whole string in order, and there must be at least two of them. - Each piece is read as a base-10 number. A piece longer than one character may not start with `"0"`. The single piece `"0"` is allowed and means zero. ### Constraints - `1 <= s.length <= 20` - `s` consists of only digits. ### Examples ```text Input: s = "123456" Output: True ``` Splitting into "1", "2", "3", "4", "5", "6" gives numbers that each go up by one. ```text Input: s = "99100101" Output: True ``` Splitting into "99", "100", "101" works even though the digit count grows from two to three. ```text Input: s = "0102" Output: False ``` "01" and "02" would be consecutive, but both have a leading zero. The only allowed first piece is "0", which forces the sequence 0, 1, 2 and the string "012", not "0102".

Overview: Decide whether a string of digits can be cut into two or more pieces whose values go up by exactly one at each step, with no leading zeros allowed. It tests enumerating a starting choice, matching strings carefully, and handling edge cases such as a growing digit count and the number zero.

Miro logo
Miro
Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

You are given a string s of digits. Determine whether s can be split into a sequence of two or more non-empty substrings such that the numerical values of the substrings form a sequential combination, meaning each number is exactly one greater than the previous number.

Leading zeros are not allowed in any substring (except for the number 0 itself, which must be the single character "0"). Return True if at least one valid split exists, otherwise return False.

Function Signature

def split_into_sequential(s: str) -> bool:

Rules

  • The pieces must cover the whole string in order, and there must be at least two of them.
  • Each piece is read as a base-10 number. A piece longer than one character may not start with "0" . The single piece "0" is allowed and means zero.

Constraints

  • 1 <= s.length <= 20
  • s consists of only digits.

Examples

Input: s = "123456"
Output: True

Splitting into "1", "2", "3", "4", "5", "6" gives numbers that each go up by one.

Input: s = "99100101"
Output: True

Splitting into "99", "100", "101" works even though the digit count grows from two to three.

Input: s = "0102"
Output: False

"01" and "02" would be consecutive, but both have a leading zero. The only allowed first piece is "0", which forces the sequence 0, 1, 2 and the string "012", not "0102".