Back to course home
0% completed
Solution: Largest Rectangle in Histogram
Problem Statement
Given an array of integers heights
, where heights[i]
represents the height of the histogram's bar, return the area of the largest rectangle
in the histogram. Each bar has width equal to 1
.
Examples
- Example 1:
- Input:
[4, 2, 3, 2]
- Input:
-
Expected Output:
8
-
Justification: The largest rectangle can be drawn from the first bar to the fourth bar, having height
2
, resulting in an area of2x4=8
. -
Example 2:
- Input:
[1,3,4,5,2]
- Input:
- Expected Output:
9
.....
.....
.....
Like the course? Get enrolled and start learning!