Course · Section 11: Working With Arrays · Lecture 149: Simple Array Methods
Given an array `heights` where `heights[i]` is the height of a vertical line at index `i`, find two lines that together with the x-axis form a container that holds the most water. Return the maximum water volume. Volume = min(heights[i], heights[j]) × (j − i).
+ 2 hidden tests run on Submit.
Two pointers from both ends, always advancing the shorter wall, find the max area in O(n) time, O(1) space.
Run your code to see results.