http://www.leetcode.com/onlinejudge
I am not able to see the difference between these two questions. To me, these two questions are same, but they are NOT.
Can someone give me some hints that explain why they are different.
Thank you
Each rectangle in the histogram represents a class of data. The width of the rectangle corresponds to the width of the class interval, and the surface of the rectangle represents the weight of the class.
The "container of water" solution will allow the water to rise above intermediate positions. With the "largest rectangle" problem, the rectangle cannot rise above intermediate bars.
The "container of water" question is not as clearly described as the largest rectangle one, however I've been asked the water one in an interview.
The container of water one is basically asking for the area of the biggest "valley" in between the bars on a histogram. Looking at the histogram in the largest rectangle example, the answer would be "1" because there are two troughs made by the graph, a 1x1 trough on the left side, and a 1x1 trough on the right side. The max of these is of course, 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With