Im trying to replicate a algorithm of a game, basically the method should take a text and a number. The method is expected to return an integer array with the number of elements specified by the second argument. The sum of all elements in the integer array should exactly match the length of the text string argument. The challenge lies in the logic, as each element in the array represents a portion of the text string, and the sum of these portions should equal the length of the text string but not orderly.
Example:
- For the input
lllChoppinglll
with 6 desired elements, the method should return:[3, 2, 2, 2, 3, 2]
- For the input
lllChoppinglll
with 12 desired elements, the method should return:[2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1]
- For the input
lllFarminglll
with 4 desired elements, the method should return:
[4, 4, 3, 2]
- For the input
lllMininglll
with 5 desired elements, the method should return:
[3, 2, 2, 2, 3]
- For the input
lllMininglll
with 4 desired elements, the method should return:
[3, 3, 3, 3]
How can I determine it?