Skip to content

Largest Histogram ​

Largest Histogram — LeetCode

Given bar heights of a histogram, find the area of the largest rectangle that fits inside it.

Approach ​

Iterate through each element. The top of the stack should be lesser than the current element -> Push current element with startIndex = i. Else, while top of stack is greater, pop the stack and calculate the maxArea. Push the current element at the end with startIndex = index of last popped element.

Calculate area for rest of the elements

Remarks ​

https://youtu.be/zx5Sw9130L0