ASAPUtils Logo ASAPUtils
Week 1

Container With Most Water

Container With Most Water with two pointers in O(n), with C++ and JavaScript solutions, a bar-chart visualizer, and a proof that moving the shorter wall can never lose the answer.

The problem

Given an array of heights where each entry is a vertical line, pick two lines that together with the x-axis hold the most water, and return that maximum area. Water is capped by the shorter of the two lines.

height = [1,8,6,2,5,4,8,3,7] -> 49 (lines at index 1 and 8)

Related Problems