Leetcode 917 Solution

This article provides solution to leetcode question 917 (boats-to-save-people)

https://leetcode.com/problems/boats-to-save-people

Solution

class Solution:
    def numRescueBoats(self, people: List[int], limit: int) -> int:
        people.sort()

        l = 0
        r = len(people) - 1

        ans = 0
        while l <= r:
            if people[l] + people[r] <= limit:
                l += 1
            r -= 1
            ans += 1

        return ans