Largest Rectangle in Histogram
Given an array of integers heights representing the bar heights of a histogram where each bar has width 1, return the area of the largest rectangle that can be formed within the histogram.
Open official problem prompt ↗Find the single widest-times-tallest rectangle that fits under the histogram's skyline.
Think of pouring water columns of different heights. Each column can spread sideways until it bumps into a shorter neighbor; the biggest puddle of uniform depth is the answer.
- Input
- heights = [2, 1, 5, 6, 2, 3]
- Output
- 10
- Why
- The bars of height 5 and 6 form a rectangle of height 5 spanning 2 columns, giving area 5 x 2 = 10, the maximum possible.
1 <= heights.length <= 10^50 <= heights[i] <= 10^4