The limiting wall
02/03Container With Most Water
Discover what you can safely leave behind.
The challenge, in plain language +
A row of upright walls stands one unit apart. Each number gives a wall's height. Choose two walls to form the sides of a container; the floor lies between them. Water can rise only as high as the shorter chosen wall. Return the largest cross-sectional area any pair can hold. Use nonnegative finite heights; with fewer than two walls, return 0.
Which fact makes it possible to eliminate many pairs at once?
This lesson uses 2D: exact positions, widths and comparisons are easier to read in one plane.