dsa · medium
Container With Most Water
You are given height where height[i] is a vertical line at x = i.
Arguments
height— height of the vertical line at each index
Choose two lines that, with the x-axis, form a container. Return the **maximum** water the container can store. Water is width × min of the two heights. The lines are infinitely thin; only the area between them counts.
Example
height = [1,8,6,2,5,4,8,3,7]
The pair at indices 1 and 8 (heights 8 and 7) has width 7, so area 7 * min(8, 7) = 49. That is the maximum.
[1,1] → width 1 × height 1 → 1.
Constraints
2 <= height.length <= 10^5 1 <= height[i] <= 10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,8,6,2,5,4,8,3,7] Expected: 49
Example 2
Input: [1,1] Expected: 1