Given n non-negative integers a1, a2, ..., an where each represents a point at coordinate (i, ai), find two lines that together with the x-axis form a container that holds the most water.
Examples
Example 1 Input:height = [1,8,6,2,5,4,8,3,7]
Output:49
Explanation: Lines at index 1 (height 8) and index 8 (height 7). Area = 7 × 7 = 49.
Constraints
▪n >= 2
▪0 <= height[i] <= 10^4
Hints
Hint 1Show
Start with two pointers at both ends — this gives maximum width.
Hint 2Show
Move the pointer with the shorter line inward.
Hint 3Show
The area is limited by the shorter line, so moving it gives a chance for a taller line.
Starter Code
Solution.js
1function maxArea(height) {
2 // Your code here
3}
Solution
Solve the problem first before reviewing the solution!