people[i] is the weight of person i. Each boat carries at most two people and a total weight of at most limit. Every person weighs at most limit. Return the fewest boats needed to carry everyone.
For people = [3, 2, 2, 1] and limit = 3 the answer is 3 ([1, 2], [2], [3]).
Example 1
Input:
boats_needed([3, 2, 2, 1], 3)
Output:
3
Example 2
Input:
boats_needed([3, 5, 3, 4], 5)
Output:
4
0 <= len(people) <= 2000001 <= people[i] <= limit <= 30000No results yet
Run your code to check it against the examples, or submit to run every test.