Largest Rectangle in a Histogram

hard
Unit 25 · BFS II0/0 to milestone

Given bar heights of width 1, find the area of the largest rectangle that fits under the histogram, in O(n) using a monotonic stack of indices with increasing heights.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Largest Rectangle in a Histogram · TechGradify