Search⌘ K
AI Features

Problem: Largest Rectangle in Histogram

Explore how to solve the largest rectangle in histogram problem using a monotonic stack. Understand how to efficiently calculate maximal rectangle areas by tracking bar heights and indices, pushing and popping from the stack to maintain increasing order. This lesson explains the algorithm's logic, implementation steps, and linear time complexity in detail.

Statement

You are given an array of integers heights, where each element represents the height of a bar in a histogram. Every bar has a width of 11.

Determine the area of the largest rectangle that can be formed within the histogram.

Constraints:

  • 11 \leq heights.length 105\leq 10^5

  • 00 \leq ...