You are given an integer array heights where heights[i] represents the height of the ith bar.
You may choose any two bars to form a container. Return the maximum amount of water a container can store.
Example 1:
Input: height = [1,7,2,5,4,7,3,6]
Output: 36Example 2:
Input: height = [2,2,2]
Output: 4Constraints:
2 <= height.length <= 10000 <= height[i] <= 1000class Solution:
def maxArea(self, heights: List[int]) -> int:
result_area = 0
i = 0
j = len(heights) - 1
while i < j:
result_area = max(result_area, self.calc_area(heights, i, j))
if heights[i] < heights[j]:
i += 1
else:
j -= 1
return result_area
def calc_area(self, heights: List[int], i: int, j: int) -> int:
return (j - i) * min(heights[i], heights[j])