You are given an array people where people[i] is the weight of the ith person, and an unlimited number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of their weights is at most limit. Return the minimum number of boats to carry every given person.
You are given an array people where people[i] is the weight of the ith person, and an unlimited number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of their weights is at most limit. Return the minimum number of boats to carry every given person.
Example 1:
Input: {"people":[1,2],"limit":3}
Output: 1
Constraints:
1≤people.length≤5×104
1≤people[i]≤limit≤3×104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"people":[1,2],"limit":3}
2 people wait on the dock. Each boat holds at most two people and at most 3 in weight.