"""
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith 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.

Notice that you may not slant the container.
"""

def max_area(height: list[int]) -> int:
    if len(height) < 2:
        return 0

    lb, rb = 0, len(height) - 1
    max_area = 0

    while lb < rb:
        area = (rb - lb) * min(height[lb], height[rb])
        max_area = max(max_area, area)
        if height[lb] <= height[rb]:
            lb += 1
        else:
            rb -= 1
    return max_area


if __name__ == "__main__":
    assert max_area([1,8,6,2,5,4,8,3,7]) == 49
