We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Stacks
- Largest Rectangle
- Discussions
Largest Rectangle
Largest Rectangle
Sort by
recency
|
621 Discussions
|
Please Login in order to post a comment
Java: For each building, I verify it's right and left buildings in order to calculate the number of buildings greater or equals current building.
public static long largestRectangle(List h) { // Write your code here int maxArea = 0;
func largestRectangle(h []int32) int64 {
}
I was looking for this thread for my youtube mp3 project. Now finally landed at the right page.
Here's my solution in C++. It's a little messy, but it works alright :)
This is one of the hard ones. I watched a YouTube video on how to solve it. And here is my code. It is pretty descriptive IMHO. Easy to read. The key is whenever the height decreases, the previous taller builds effectively reached the end of their lives. And we can calculate their max areas. And we can extend the starting position of the new lower height to the leftest one that is 'killed' by this new lower height. Adding a '0' to the end of the height so that at the end, all the leftover heights are killed by this '0' and we can calculate their max areas.
def largestRectangle(h):