We’re preparing your current view and syncing the latest data.
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container and n is at least 2.
An array of n non-negative integers representing the heights of the vertical lines.
An integer representing the maximum amount of water a container can store.
2 <= n <= 10^5 0 <= heights[i] <= 10^4
Example 1
Input
[1,8,6,2,5,4,8,3,7]
Output
49
Explanation
The max area is formed between the lines at index 1 (height 8) and index 8 (height 7), with width 7 and height 7, resulting in area 49.