84. Largest Rectangle in Histogram
Practice Largest Rectangle in Histogram for free on NudgeCode: Hard, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
heights describes a bar chart where every bar is 1 unit wide and bar i is heights[i] tall. Return the area of the largest rectangle that fits entirely inside the bars.
Example
heights = [2,1,5,6,2,3] -> 10 (the bars 5 and 6, height 5, width 2)
heights = [2,4] -> 4
Constraints
- 1 <= heights.length <= 10^5
- 0 <= heights[i] <= 10^4