An algorithm that sorts a list of values into a minimum amount of groups, under condition that the sum of values within each group does not exceed N

The list of values: a = [1,4,3,5,7,9,5,4,5,6,3,2,1,9,4,3,6,4,3,4,6,7]

Group the values so that the the sum of the values in each group does not exceed 10. The aim is to group the values in such a way to have the minimum amount of groups.

In example: Group 1 = [1,9] Group 2 = [2,3,5] etc.

I am looking for an algorithm to solve this problem. Any help would be appreciated, even if it is just setting me on track with what this type of problem is called.



Read more here: https://stackoverflow.com/questions/68471661/an-algorithm-that-sorts-a-list-of-values-into-a-minimum-amount-of-groups-under

Content Attribution

This content was originally published by Bhukusheni at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: