Skip to content
BASA DSA

Largest Rectangle In Histogram

HardStack

Return the greatest rectangular area supported by consecutive unit-width histogram bars.

Example 1

Input
heights = [3,1,3,3]
Output
6

Explanation

The final two height-three bars support area 6, exceeding the width-four height-one rectangle.

Example 2

Input
heights = [2,2,2]
Output
6

Explanation

All three bars support height 2 across width 3, giving 6.

Example 3

Input
heights = [0]
Output
0

Explanation

A zero-height bar supports area zero.

Constraints

  • 1 <= len(heights) <= 100000
  • Heights are 0..10000

Function contractlargestRectangleAreaArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…