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: 36 Example 2:
Input: height = [2,2,2]
Output: 4
In [3]:
def maxArea(heights):
l,r=0,len(heights)-1
maxarea=0
while l<r:
area=0
if heights[l]<heights[r]:
area = (r-l)*heights[l]
l=+1
elif heights[l]>=heights[r]:
area = (r-l)*heights[r]
r-=1
maxarea = max(maxarea,area)
return maxarea
In [4]:
maxArea([2,2,2])
Out[4]:
4
In [5]:
maxArea([1,7,2,5,4,7,3,6])
Out[5]:
36