Given an array 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: Input: heights = [2,1,5,6,2,3] Output: 10 Explanation: The largest rectangle is formed by the bars 5 and 6, with area 10. Pattern focus: Monotonic Increasing Stack for Span / boundary discovery.
heights = histogram bar heights
maximum rectangle area in the histogram
Example 1:
Input:
heights = [2,1,5,6,2,3]
Output:
10
Explanation:
The rectangle covering heights 5 and 6 with width 2 gives the best area.
Example 2:
Input:
heights = [2,4]
Output:
4
Explanation:
The tallest single bar may be optimal when the width is small.