From b406a073c9611bcac50f6ed963b1013daa98dcb7 Mon Sep 17 00:00:00 2001
From: Barrett Ruth
def maxArea(height: list[int]) -> int:
- area = 0
+ ans = 0
l, r = 0, len(height) - 1
+
while l < r:
width, min_height = r - l, min(height[l], height[r])
- area = max(area, width * min_height)
+ ans = max(ans, width * min_height)
+
while l < r and height[l] <= min_height:
l += 1
while l < r and height[r] <= min_height:
r -= 1
- return area
+
+ return ans
def minimum_rescue_boats(people: list[int], limit: int) -> int:
- boats = 0
- light = 0
- heavy = len(people) - 1
+ ans = 0
+ l, r = 0, len(people) - 1
people.sort()
- while light <= heavy:
- if light == heavy:
- boats += 1
+ while l <= r:
+ if l == r:
+ ans += 1
break
- elif people[light] + people[heavy] <= limit:
- boats += 1
- light += 1
- heavy -= 1
+ elif people[l] + people[r] <= limit:
+ ans += 1
+ l += 1
+ r -= 1
else:
- boats += 1
- heavy -= 1
+ ans += 1
+ r -= 1
- return boats
+ return ans