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.


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 1

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.