Leetcode 917 Solution
This article provides solution to leetcode question 917 (boats-to-save-people)
Access this page by simply typing in "lcs 917" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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