Given an array of integers 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.
Input:
heights = [2,1,5,6,2,3]Output:
10
This problem asks you to determine the maximum rectangular area that can be formed within a histogram. A brute-force approach would check every possible range, but that would be inefficient. The key insight is to determine, for each bar, how far it can extend to the left and right while maintaining its height as the minimum. A common efficient strategy uses a monotonic stack to find the first smaller element on both sides, allowing computation of the maximum area in linear time.