You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store.
Example 1
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: Use the lines at index 1 (height 8) and index 8 (height 7). The water level is limited by the shorter line, 7, and the width is 8 - 1 = 7, so the area is 7 × 7 = 49.
Example 2
Input: height = [1,1]
Output: 1
Explanation: There are only two lines, both of height 1, and they are 1 apart, so the area is 1 × 1 = 1.
Example 3
Input: height = [4,3,2,1,4]
Output: 16
Explanation: The two outer lines both have height 4 and are 4 apart, giving 4 × 4 = 16. Any inner pair is narrower and at most as tall.
Start with the widest container (left=0, right=n-1). Move the shorter side inward since it limits the height and we're reducing width.
Run checks all cases above. Submit evaluates all test cases.