Container With Most Water

Given an array of non-negative integers heights, find two lines that together with the x-axis form a container that holds the most water. Return the maximum area.

Input Format

height = array of non-negative integers

Output Format

Maximum area contained between two lines

Constraints

  • 2 <= height.length <= 10^5; 0 <= height[i] <= 10^4

Examples

Example 1:

Input:

height = [1,8,6,2,5,4,8,3,7]

Output:

49

Explanation:

The best container is formed by height[1]=8 and height[8]=7, area = 7*7=49.

Loading...
Container With Most Water - Arrays DSA Problem