11. Container With Most Water
Medium · Array
You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the i-th line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container such that the container holds the most water.
Return the maximum area of water the container can store. You may not slant the container.
Examples
Example 1 Input: [1,8,6,2,5,4,8,3,7] Output: 49 Explanation: The vertical lines at index 1 (height 8) and index 8 (height 7) form a container. The width is 8 - 1 = 7 and the height is min(8, 7) = 7, so the area is 7 × 7 = 49.
Example 2 Input: [1,1] Output: 1 Explanation: The two lines at index 0 and 1 both have height 1. The width is 1 - 0 = 1 and the height is min(1, 1) = 1, so the area is 1 × 1 = 1.
Constraints
- Standard input/output constraints apply