Given n non-negative integers height where each represents a point at coordinate (i, height[i]). n vertical lines are drawn such that the two endpoints of the line i is at (i, height[i]) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
Notice that you may not slant the container.
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
Input: height = [1,1]
Output: 1
Input: height = [4,3,2,1,4]
Output: 16
n == height.length2 <= n <= 10^50 <= height[i] <= 10^4When the function maxArea is called with the given example inputs, the expected outputs are:
[1,8,6,2,5,4,8,3,7], the output is 49.[1,1], the output is 1.[4,3,2,1,4], the output is 16.console.log(maxArea([1,8,6,2,5,4,8,3,7])); // Output: 49
console.log(maxArea([1,1])); // Output: 1
console.log(maxArea([4,3,2,1,4])); // Output: 16
Memory: 0
CPU: 0