Container With Most Water
Pick the two lines that hold the most water by starting with the widest container and always moving the shorter wall.
01The problem
height[i] is a vertical line at position i. Pick two lines that, with the x-axis, hold the most water. The water level is the shorter line, and the width is the distance between them. Return the maximum area. You can't tilt the container.
| Input | Output | Why |
|---|---|---|
[1, 8, 6, 2, 5, 4, 8, 3, 7] | 49 | lines 8 and 7, 7 apart |
[1, 1] | 1 |
Constraints: 2 to 100,000 lines, heights 0 to 10,000.
Loading the rest of the lesson…