Boats to Save People
Try to solve the Boats to Save People challenge.
We'll cover the following
Statement
A big ship with numerous passengers is sinking, and there is a need to evacuate these people with the minimum number of life-saving boats. Each boat can carry, at most, two persons however, the weight of the people cannot exceed the carrying weight limit of the boat.
We are given an array, people
, where people[i]
is the weight of the person, and an infinite number of boats, where each boat can carry a maximum weight, limit
. Each boat carries, at most, two people at the same time. This is provided that the sum of the weight of these people is under or equal to the weight limit.
You need to return the minimum number of boats to carry all persons in the array.
Constraints:
-
people.length
-
people[i]
limit