Given n non-negative integers height where each represents a vertical line at coordinate 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 (area).
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Input: height = [1,1]
Output: 1
Input: height = [4,3,2,1,4]
Output: 16
Runner expects a single line stdin with a JSON array of integers (e.g. [1,8,6,2,5,4,8,3,7]) and prints the integer maximum area.
No submissions yet.
Share two-pointer greedy solution, complexity analysis, and corner cases.