Container With Most Water
heights[i] is the height of a vertical wall standing at position i on a line. Choose two walls: together with the ground they form a container holding (distance between them) × (height of the shorter wall) units of water. Return the most water any two walls can hold.
Constraints
- 2 ≤ length of
heights≤ 100,000 - 0 ≤
heights[i]≤ 10,000
Example 1
Input
heights = [1,8,6,2,5,4,8,3,7]
Output
49
Why:
The walls at positions 1 (height 8) and 8 (height 7): 7 apart, 7 high.
Example 2
Input
heights = [1,1]
Output
1
Why:
1 apart, 1 high.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –