Loading...
Loading...
Loading...
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the i-th line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store.
You may not slant the container.
Input: Array height of non-negative integers.
Output: Integer — maximum container area.
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: Pick lines at index 1 (height 8) and index 8 (height 7). Width = 7, height = min(8,7) = 7. Area = 49.
Input: height = [1,1]
Output: 1
l=0, r=n-1. Area = (r-l) * min(height[l], height[r]). Track max. Move whichever pointer points at the smaller line inward — moving the taller line can only reduce or hold area constant.min(...) and reduces width.n == height.length 2 <= n <= 10^5 0 <= height[i] <= 10^4