Search⌘ K
AI Features

Problem: Largest Rectangle in Histogram

Explore how to determine the largest rectangular area in a histogram by implementing a stack-based algorithm. This lesson guides you through using a monotonic stack to track bar heights and systematically compute the maximum area in a single pass, enhancing your understanding of stacks and algorithm optimization in C#.

Statement

You are given an integer array 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

  • ...