I have an array with the following elements:
a <- c(2, 2.99, 3.95, 3, 2, 2, 2, 9.95, 9, 16.89, 8.99, 15, 15, 15, 14, 14, 16.14, 16.14, 16.14, 15.14)
I'm looking for a way to split this array into the minimum number of subarrays such that the sum of values within each subarray is less than 20.
I tried to solve this by sorting them in ascending order and starting by grouping smaller values first, but I don't think that is the best (or accurate) way to solve this.