#K78257. Maximum Rectangle Area in a Histogram

    ID: 35046 Type: Default 1000ms 256MiB

Maximum Rectangle Area in a Histogram

Maximum Rectangle Area in a Histogram

Given a histogram represented by a list of positive integers where each integer denotes the height of a building, compute the maximum rectangular area that can be formed in the histogram. The rectangle's area is calculated as (\text{height} \times \text{width}), where width is the number of consecutive buildings included. An efficient solution uses a stack to track indices of buildings. For example, if the heights are [2, 1, 5, 6, 2, 3], the maximum rectangle area is (10).

inputFormat

The first line of the input contains an integer (n) representing the number of buildings. The second line contains (n) space-separated positive integers that represent the heights of the buildings.

outputFormat

Output a single integer which is the maximum rectangular area that can be obtained from the given histogram.## sample

6
2 1 5 6 2 3
10

</p>