You are given an array of integers heights where heights[i] represents the height of the i-th vertical line. There are n vertical lines drawn such that the two endpoints of line i are (i, 0) and (i, heights[i]).
Your task is to find two of these lines that, together with the x-axis, form a container that holds the most water.
Note that you may not slant the container.
Return the maximum amount of water this container can store.
[1, 8, 6, 2, 5, 4, 8, 3, 7]
49
The maximum area of water the container can hold is 49. This is formed by lines at index 1 (height 8) and index 8 (height 7). The width is 8 - 1 = 7, and the height is min(8, 7) = 7. Area = 7 * 7 = 49.
[1, 1]
1
With two lines of height 1 at indices 0 and 1, the width is 1 - 0 = 1, and the height is min(1, 1) = 1. Area = 1 * 1 = 1.
[4, 3, 2, 1, 4]
16
The lines at index 0 (height 4) and index 4 (height 4) form the container. The width is 4 - 0 = 4, and the height is min(4, 4) = 4. Area = 4 * 4 = 16.
[1, 8, 6, 2, 5, 4, 8, 3, 7]
49