Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Largest Rectangle in Histogram
Bookmark
Input
Example 1
Example 2
Example 3
Ascending
Descending
Custom
heights
=
[2, 1, 5, 6, 2, 3]
histogram
2
1
5
6
2
3
0
1
2
3
4
5
stack
(empty)
the biggest rectangle that fits under the bars
histogram
2
1
5
6
2
3
0
1
2
3
4
5
stack
(empty)
the biggest rectangle that fits under the bars
max area =
0
histogram
2
1
5
6
2
3
0
1
2
3
4
5
i
stack
2
bar 0
top
bar 1, height
1
max area =
2
histogram
2
1
5
6
2
3
2 × 1 = 2
0
1
2
3
4
5
i
stack
(empty)
maxArea =
2
max area =
2
histogram
2
1
5
6
2
3
max 2
0
1
2
3
4
5
i
stack
1
bar 1
5
bar 2
top
bar 3, height
6
max area =
2
histogram
2
1
5
6
2
3
max 2
0
1
2
3
4
5
i
stack
1
bar 1
5
bar 2
6
bar 3
top
2
<
6
pop and measure
max area =
6
histogram
2
1
5
6
2
3
max 6
5 × 2 = 10
0
1
2
3
4
5
i
stack
1
bar 1
top
area =
5
×
2
=
10
max area =
10
histogram
2
1
5
6
2
3
max 10
0
1
2
3
4
5
i
stack
1
bar 1
2
bar 4
top
bar 5, height
3
max area =
10
histogram
2
1
5
6
2
3
max 10
3 × 1 = 3
0
1
2
3
4
5
stack
1
bar 1
2
bar 4
top
maxArea =
10
max area =
10
histogram
2
1
5
6
2
3
max 10
2 × 4 = 8
0
1
2
3
4
5
stack
1
bar 1
top
maxArea =
10
max area =
10
histogram
2
1
5
6
2
3
max 10
0
1
2
3
4
5
stack
(empty)
largest rectangle =
10
algo
master
.
io
Step:
Start of algorithm
0 / 32
Input
Example 1
Example 2
Example 3
Ascending
Descending
Custom
heights
=
[2, 1, 5, 6, 2, 3]
0 / 32
algo
master
.
io
Step:
Start of algorithm