Is there an existing algorithm that can solve the following problem?
Problem
Given an list N comprised of integers of various values, shard the list into k buckets such that:
- The sum of the integers in each bucket are roughly evenly divided (as much as possible
- Only consecutive integers are placed in the same bucket
Example:
Given k (the number of buckets) = 4
List N = [4 1 2 6 19 1 10 3 2 2]
A Valid Solution
[4 1 2] [6] [19] [1 10 3 2 2]
(Since the bucket weights add up to 7, 6, 19, 18
)
An Invalid Solution
[1 1 2 2 2 3] [1 4 6] [10] [19]
(Where the bucket weights would add up to 11, 11, 10, 19
)
It's invalid because the buckets no longer contain only numbers that were adjacent in the original list.
Thanks!