Here is the implementation:
function maxArea(height):
left = 0
right = height.length - 1
maxWater = 0
while left < right:
width = right - left
h = min(height[left], height[right])
maxWater = max(maxWater, width * h)
if height[left] < height[right]:
left += 1
else:
right -= 1
return maxWater
This runs in time and space (excluding input).