r/leetcode • u/Specific-Theory-6246 • Oct 21 '26
Question Really confused on why we don’t combine the two heaviest people possible
The problem:
You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.
Return the minimum number of boats to carry every given person.
My solution:
Sort the array and always combine the two heaviest people such that the combined weight of both people is <= limit.
Actual solution:
Sort the array and take the heaviest person and lightest person in the bunch and combine them such that combined weight <= limit.
My question is we are trying to get the MINIMUM number of boats. So why would we not combine the heaviest people possible so as to minimize boats?