Largest Rectangle in Histogram
Try to solve the Largest Rectangle in Histogram problem.
We'll cover the following
1 of 2
2 of 2
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Largest Rectangle in Histogram
1
What is the output if the following array of heights is given as input?
heights = [1, 2, 5, 7, 3, 9]
|-|
|-|
|-| |-|
|-| |-|
|-|-| |-|
|-|-| |-|
|-|-|-|-|
|-|-|-|-|-|
|-|-|-|-|-|-|
1 2 5 7 3 9
A)
21
B)
27
C)
10
D)
12
Question 1 of 30 attempted
Try it yourself#
Implement your solution in the following coding playground.
An optimal solution to this problem runs in O(n) time and takes O(n) space.
Python
usercode > main.py
Largest Rectangle in Histogram
You might want to go over the Stacks pattern again.
Solution: Evaluate Reverse Polish Notation
Solution: Largest Rectangle in Histogram