Given an array of bar heights forming a histogram where each bar has width 1, find the area of the largest rectangle that can be formed within the histogram.
heights = [2,1,5,6,2,3]10heights = [2,4]4Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A stack is last-in-first-out — the most recently added item is the first one removed. It's the natural fit whenever "the most recent unmatched thing" matters, like nested brackets or undo history.
Original problem on LeetCode ↗