Container With Most Water Problem

Container With Most Water Problem — ExecCode Medium DSA Practice

Solve the Container With Most Water problem on ExecCode. Free online medium DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Choose two vertical lines that hold the most water. The area is width times the shorter height, so always move the shorter side inward to search for a taller boundary.

Examples

Input height = [1,8,6,2,5,4,8,3,7]; Output 49. Input height = [2,3,10,5,7,8,9]; Output 36

Constraints

n == height.length 2 ≤ n ≤ 10⁵ 0 ≤ height[i] ≤ 10⁴

Practice Container With Most Water free on ExecCode. Browse DSA problems, topic map, and placement guides.