All questions
MediumArrays · Two Pointers
Container With Most Water
Written by a community member · · 1 attempt · 100% pass
0
Given an integer array height of length n, where the endpoints of the ith vertical line are (i, 0) and (i, height[i]), choose two different lines that, together with the x-axis, form a container. Return the maximum amount of water the container can store. The container's area is min(height[i], height[j]) * (j - i), and the sides may not be slanted.
Constraints:
2 <= len(height) <= 100,0000 <= height[i] <= 10,000
Your solution should run in O(n) time and use O(1) extra space.
Examples:
max_area([1,8,6,2,5,4,8,3,7])returns49.max_area([1,1])returns1.