Facebook Pixel

Largest Rectangle In Histogram | Monotonic Stack

Given an array of integers heights representing the height of bars in a histogram, find the largest rectangle that can fit inside the histogram.

Parameter

  • heights: A list of integer representing the height of each bar in the histogram. Each bar has a width of 1.

Result

  • The area of the largest rectangle that can fit inside the histogram.

Example

Example 1

Input: heights = [3, 5, 6, 2, 1, 4]

Output: 10

Explanation:

Constraints

  • 1 <= len(heights) <= 10^5
  • 1 <= heights[i] <= 10^4

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro