881. Boats to Save People
Practice Boats to Save People for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
people[i] is the weight of person i. Each boat carries at most two people whose total weight is at most limit. Return the minimum number of boats needed to carry everyone.
Example
people = [3,2,2,1], limit = 3 -> 3 ([1,2], [2], [3])
Constraints
- 1 <= people.length <= 5 * 10^4
- 1 <= people[i] <= limit <= 3 * 10^4