Largest Rectangle in Histogram — C# Coding Problem
Difficulty: hard | Category: stack
Problem Description
Given an array of integers `heights` representing the histogram's bar heights (each bar has width `1`), return the **area of the largest rectangle** in the histogram. **Constraints:** - `1 <= heights.length <= 10⁵` - `0 <= heights[i] <= 10⁴` **Hint:** Use a monotonic stack. For each bar, find the left and right boundaries where it is the shortest.
Examples
Example 1
Input: heights = [2,1,5,6,2,3]
Output: 10
Explanation: Rectangle of height 5 spans indices 2–3 (width 2).
Example 2
Input: heights = [2,4]
Output: 4