medium
Container With Most Water
You are given an array of vertical line heights at unit-spaced positions. Pick two lines so that, together with the x-axis, they enclose the largest possible amount of water. Return that area (width × shorter height).
Constraints
- 2 ≤ n ≤ 10^5
- 0 ≤ height[i] ≤ 10^4
Examples
in: height = [1,8,6,2,5,4,8,3,7]
out: 49
Lines at indices 1 and 8 (heights 8 and 7) span width 7.
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.