Container With Most Water
Problem statement
Given an array height, where height[i] is the height of a vertical line at position i, choose two lines that together with the horizontal axis form a container.
Return the maximum amount of water the container can hold. The area between indices left and right is (right - left) * min(height[left], height[right]).
Function
maxArea(height: int[]) → intExamples
Example 1
height = [1,8,6,2,5,4,8,3,7]return = 49Indices 1 and 8 have limiting height 7 and width 7.
Example 2
height = [1,1]return = 1The only pair has width and height 1.
Constraints
2 <= height.length <= 100000.0 <= height[i] <= 10000.- The maximum area fits in a signed 32-bit integer.
Source note: Author-written prompt excerpt retained for source fidelity.