The difference between the “Biggest rectangle in the histogram” and “The container with most water”

http://www.leetcode.com/onlinejudge

I do not see the difference between the two questions. For me, these two questions are the same, but they are NOT.

Can someone give me some tips that explain why they are different.

thanks

+4
source share
3 answers

The solution "container with water" will allow water to rise above the intermediate positions. With the “largest rectangle” problem, a rectangle cannot rise above intermediate columns.

+11
source

The question "water container" is not so clearly marked as the largest rectangle, but I am asked about water in an interview.

The water container basically asks for the area of ​​the largest “valley” between the bars on the histogram. Looking at the histogram in the example with the largest rectangle, the answer will be “1”, because there are two depressions made by the graph, the left side is 1x1 and the left side is 1x1 on the right side. Their maximum, of course, is 1.

+1
source

they are very similar. I understand that the difference is that the “container with water” will be the left wall, the right wall and the bottom (x axis) (and some lines between them may be short), it is open at the top. while in the "largest rectangle" all the histograms making up the rectangle would have to reach the upper region.

0
source

Source: https://habr.com/ru/post/1435424/


All Articles