dfs
that takes the current index i
, the number of splits n
, and the previous numerical value p
as arguments.i
is equal to the length of the string and n
is greater than 1, return True
as we have successfully split the string.i
to the end of the string.s[i:j+1]
to an integer v
.p
is None
(first split) or v
is exactly one less than p
, recursively call dfs
with j + 1
, n + 1
, and v
.True
, propagate the True
value up the call stack.False
.dfs
with initial parameters 0
, 0
, and None
and return its result.