Link: 881. Boats to Save People - Medium

Question

Restate the problem


Method 1 - Two pointer
Method 2

Method

Approach

(discussed at lease two approach?)

Complexity

Edge Case

Code

class Solution:
    def numRescueBoats(self, people: List[int], limit: int) -> int:
        people.sort()
        boat = 0
        left = 0
        right = len(people) - 1
 
        while left <= right:
            if people[left] + people[right] <= limit:
                left += 1
                right -= 1
                boat += 1
            else:
                right -= 1
                boat += 1
        
        return boat

History

Jan-25-2026 Peeked

  • use wrong approach