AI Features

Container with Most Water

Given an array of the heights of vertical lines, find two lines that, together with the horizontal axis, form a container that holds the most water.

Statement

Given an array of heights, which represents the heights of vertical lines drawn on a graph. Find two lines that form a container that holds the most water when combined with the horizontal axis. The height of this container will be the shorter of the two lines:

Note: We cannot tilt any water containers.

Example

Example 1

Sample input

The array below represents the heights of the vertical lines:

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

Expected output

49

Example 2

Sample input

The array below represents the heights of the vertical lines:

[1, 1]
...