#K82712. Maximum Container Area
Maximum Container Area
Maximum Container Area
Given a list of non-negative integers representing the heights of vertical lines drawn on the x-axis (where the x-coordinate of the i-th line is i), find two lines that together with the x-axis form a container, such that the container can hold the maximum amount of water. The area of the container is computed as:
\( \text{area} = (j - i) \times \min(\text{height}[i], \text{height}[j]) \)
where \( i \) and \( j \) are the indices of the chosen lines with \( i < j \). It is guaranteed that the list has at least one element. Note that if there is only one building, no container can be formed and the area is 0.
Your task is to compute and output the maximum possible area.
inputFormat
The first line contains an integer ( n ) representing the number of buildings. The second line contains ( n ) space-separated integers representing the heights of the buildings.
outputFormat
Output a single integer which is the maximum area of water that can be contained.## sample
9
1 8 6 2 5 4 8 3 7
49
</p>