14. Container With Most Water

height[i] is the height of a vertical line at position i. Pick two lines that, together with the x-axis, hold the most water. Return that amount: min(height[i], height[j]) × (j − i).

Example 1

Input: height = [2,5,1,4,3]
Output: 9
Explanation: Lines at positions 1 (height 5) and 4 (height 3): min(5, 3) × 3 = 9.

Example 2

Input: height = [4,3,2,1,4]
Output: 16
Hint 1

Start with the widest container.

Hint 2

Moving the taller line can never help: the width shrinks and the height is still capped by the shorter line.

Two PointersGreedy