Boats to Save People
Item people[i] of the list people is the weight of person i. Each boat carries at most two people at once, and their total weight must not exceed limit. Every single person weighs at most limit.
Return the fewest boats needed to carry everybody.
Example 1
people [1,2]
limit 3
returns 1
Both fit in one boat (1 + 2 = 3).
Example 2
people [3,2,2,1]
limit 3
returns 3
Boats: (1,2), (2), (3): 3 boats.
Constraints
1 <= len(people) <= 201 <= people[i] <= limit <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.