The challenge is really simple: given a number, you split its digits into an array of smaller numbers such that the resulting numbers are non-decreasing. The catch is that you have to split it such that the array length is maximal.
Confused?
- You are given a positive integer via STDIN (or closest alternative), command-line argument or function argument in any convenient, unambiguous input format.
- You have to partition the number's decimal digits into contiguous, disjoint groups.
- The array of numbers represented by these digit groups should be sorted (in the usual, non-decreasing order) without rearranging the groups.
- In cases where more than one such partition exists, you have to partition the input into as many numbers as possible. In the case of ties, return one such result.
- You can output the array to STDOUT (or closest alternative) or as a function return value. In case of STDOUT (or closest alternative), the array should be printed in any convenient, unambiguous list format.
- The split numbers should not have leading zeroes. So for instance
1002003
cannot be printed as either[1, 002, 003]
or[1, 2, 3]
and the only valid answer for it is[100, 2003]
.
Test cases:
123456 -> [1, 2, 3, 4, 5, 6]
345823 -> [3, 4, 5, 8, 23]
12345678901234567890 -> [1, 2, 3, 4, 5, 6, 7, 8, 90, 123, 456, 7890]
102 -> [102]
302 -> [302]
324142 -> [3, 24, 142] OR [32, 41, 42]
324142434445 -> [32, 41, 42, 43, 44, 45]
1356531 -> [1, 3, 5, 6, 531]
11121111111 -> [1, 1, 1, 2, 11, 11, 111]
100202003 -> [100, 202003]
Scoring
This is code-golf so shortest code in bytes wins.