Container With Most Water

Medium

height[i] is the height of a vertical line at x-coordinate i. Two lines together with the x-axis form a container.

Return the maximum amount of water such a container can hold.

Example 1

maxArea()
Input
height = [1,8,6,2,5,4,8,3,7]
Output
49

Example 2

maxArea()
Input
height = [1,1]
Output
1
Constraints
n == height.length
2 <= n <= 10^5
0 <= height[i] <= 10^4

Topics

ArraysTwo PointersGreedy

Implement maxArea in the editor and return the answer — printing it is never graded.