Container With Most Water

Given an integer array height, where height[i] is the height of a vertical line at index i, choose two lines that form a container with the x-axis. Return the…

Given an integer array `height`, where `height[i]` is the height of a vertical line at index `i`, choose two lines that form a container with the x-axis. Return the maximum amount of water any such container can hold. The area between indices `left` and `right` is the distance between them multiplied by the shorter of their two heights. The container cannot be tilted.

- `2 <= height.length <= 10^5` - `0 <= height[i] <= 10^4` - The answer fits in a signed 32-bit integer. - The interactive visualizer accepts at most 12 values; longer valid arrays are execution-only.

Example 1: input height = [1,8,6,2,5,4,8,3,7]; output 49. The lines at indices 1 and 8 give min(8, 7) × (8 − 1) = 49.

Example 2: input height = [1,1]; output 1.

Category: Two Pointers. Topic: two-pointers. Difficulty: Medium. Patterns: two-pointers, greedy.