Search⌘ K
AI Features

Solution: Boats to Save People

Explore the greedy algorithm to determine the minimum number of boats required to rescue people given weight and capacity constraints. Understand how to pair the heaviest and lightest individuals effectively by sorting and using two pointers, optimizing time and space complexity in coding interview challenges.

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} ...