Loading...
You are given an array values of positive integers and a positive integer capacity, with every value at most capacity.
Split all the values into groups of at most two values each, where the sum of each group is at most capacity.
Return the minimum possible number of groups.
Input: values = [7,2,3,9], capacity = 10
Output: 3
Explanation: The groups {2,7}, {3} and {9} work: 9 cannot pair with anything, and after pairing 2 with 7, the 3 is left alone. Two groups are impossible.
Input: values = [1,2,3,4], capacity = 5
Output: 2
Explanation: Pair 1 with 4 and 2 with 3; both sums equal the capacity.
values.length ≤2⋅105capacity ≤109values[i] ≤ capacityClick "Run" to test with sample cases or "Submit" to run all tests.