Math Fundamentals18 sections · 814 units
Open in Course

Problem - Container With Most Water

LeetCode 11

You are given an array heightheight of length nn. Each element represents the height of a vertical line. Find two lines that together with the x-axis form a container that holds the most water.

The area of water is width×min height\text{width} \times \text{min height}. If lines are at indices ii and jj where i<ji < j, then area =(ji)×min(height[i],height[j])= (j - i) \times \min(height[i], height[j]).

Find the maximum area. Before reading on, think about what formula you're maximizing.