You are given an array values of positive integers and a positive integer limit, with every value at most limit.
Partition all the values into groups so that the sum of each group is at most limit.
Return the minimum possible number of groups.
Examples
Example 1
Input: values = [4,8,6,1], limit = 10
Output: 2
Explanation: The groups {4,6} (sum 10) and {8,1} (sum 9) cover all values within the limit. One group cannot hold everything, so 2 is optimal.
Example 2
Input: values = [6,6,6], limit = 10
Output: 3
Explanation: No two values fit together (6 + 6 > 10), so each value needs its own group.
Constraints
1≤values.length≤17
1≤limit≤109
1≤values[i]≤limit
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up