Each value in heights represents a vertical line at that index. Choose two lines that hold the greatest amount of water.
Return the maximum area. The area is the shorter height multiplied by the distance between the lines.
Inputheights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output49
The lines of heights 8 and 7 at indices 1 and 8 form the largest container. Its width is 7 and the shorter line is 7 units tall, so the area is 7 × 7 = 49.
Inputheights = [1, 1]
Output1
There is only one pair of lines. Its width and shorter height are both 1, so the area is 1 × 1 = 1.
2 ≤ heights.length ≤ 100,0000 ≤ heights[i] ≤ 10,000