The question I am asking has been asked/answered here, however the answer provided uses a Python specific library, and as such does not help.
I am attempting to build an algorithm, that given:
- A string
s
with lengthl
- A number of "splits"
n
Will return n
number of substrings ss
, whos' length ssl
cannot be more than 1 apart from each other.
Examples:
Split ATestString
into 3 parts:
- The following would be valid:
["ates", "tstr", "ing"]
,[4, 4, 3]
- Whereas this would not:
["atest", "strin", "g"]
,[5, 4, 1]
Split AnotherTestString
into 4 parts:
- Valid:
["Anoth", "erTe", "stSt", "ring"]
,[5, 4, 4, 4,]