Given an array of integers representing the heights of vertical containers, calculate the maximum amount of water that can be contained between them. The water can only be trapped if there are taller containers on both sides. The width of each container is 1.
Example 1:
Input: heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output: 49
The maximum water is trapped between the containers at indices 1 and 8, which is (8-1) * (8-1) = 49.
Example 2:
Input: heights = [1, 1]
Output: 1
The only possible water trapped is between the two containers, which gives a volume of 1.
2 <= heights.length <= 10^50 <= heights[i] <= 10^4heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]Output49WhyThe maximum water trapped is between heights 8 and 7, giving a width of 7 and height of 7.heights = [1, 1]Output1WhyThe only possible water trapped is between the two containers, which gives a volume of 1.2 <= heights.length <= 10^50 <= heights[i] <= 10^4def max_area(heights: list[int]) -> int: