Largest Rectangle in a Histogram
Bars of width 1 and given heights stand in a row. Print the area of the largest axis-aligned rectangle fitting inside the histogram.
Input: the first line has N; the second line has the N heights.
Output: the maximum rectangle area.
Constraints:
- 1 ≤ N ≤ 105
- 0 ≤ hi ≤ 109
Sample Tests
Input 1
6 2 1 5 6 2 3
Output 1
10
Input 2
2 2 2
Output 2
4
Discussion (opens after you solve — no spoilers before)
No comments yet.