Search⌘ K
AI Features

Solution: Boats to Save People

Explore how to solve the problem of evacuating people with minimum boats by applying the greedy algorithm. Learn to pair the lightest and heaviest individuals efficiently under weight constraints, improving your understanding of optimization and two-pointer techniques in coding interviews.

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 ithi^{th} ...