Problem 61171. Hình chữ nhật lớn nhất trong biểu đồ Histogram
- 1 <= heights.length <= 105
- 0 <= heights[i] <= 104
Solution Stats
Problem Comments
-
6 Comments
Quite a few of the tests appear to be incorrect.
I agree with Christian, test cases 2, 8, 14, 22, 24, 26, and 30 are incorrect.
Yes, I agree. In fact, test 2 is used as an example in the statement of the problem, and the answer is listed as 4. But in test 2, the correct answer is said to be 6.
By the way, you can quickly check that some of the tests are wrong just by factorizing the supposed correct area. For example, in test 2, if 6 were the correct result, there would have to be a rectangle of height 3 and width 2, or a rectangle of height 2 and width 3. Neither of these works. This test is very handy for the longer histograms.
I found the commonality between the erroneous test cases and thus was able to modify my code to get past them:
heights=[max(heights),heights];
Looking at Sune's solution, it would seem the "window" (or width of the box) is one more than it needs to be if it encompasses the first height value.
Thanks, Matthew!
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!