Loading...
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.
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.
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.
values.length ≤17limit ≤109values[i] ≤ limitClick "Run" to test with sample cases or "Submit" to run all tests.