Solution: Boats to Save People
Explore how to apply a greedy algorithm to efficiently solve the Boats to Save People problem. Learn to pair the heaviest and lightest individuals within a weight limit to minimize boat usage, improving from a naive O(n²) approach to an optimized O(n log n) solution through sorting and two-pointer technique.
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 ...