Skip to content
CodeShare
All problems

Largest Rectangle in Histogram

Find the biggest rectangle that fits under a bar chart.

HardArraysStack

Given an array heights describing a histogram where every bar has width 1, return the area of the largest rectangle that fits entirely inside the histogram.

Examples

Example 1
Input
heights = [2, 1, 5, 6, 2, 3]
Output
10
Why
The bars of height 5 and 6 make a 2 × 5 rectangle.
Example 2
Input
heights = [2, 4]
Output
4

Constraints

  • 1 <= heights.length <= 10^5
  • 0 <= heights[i] <= 10^4