0084. Largest Rectangle in Histogram

https://leetcode.com/problems/largest-rectangle-in-histogram

Description

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.

Example 1:

Example 2:

Constraints:

  • 1 <= heights.length <= 105

  • 0 <= heights[i] <= 104

ac1: stack

stack & array push -1 at first, like #32 push 0 at last, like this one #84

This is more intuitive without pushing -1 or 0:

Last updated

Was this helpful?