Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 47s1 days 16 hours 1 minutes 47 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 47s1 days 16 hours 1 minutes 47 seconds.

Sign in to watch this lesson
Advanced - Dynamic Programming · 4:34
To find the largest all-zero rectangle in a grid, we fix the rectangle's bottom row and sweep it downward, keeping one number per column: the row of the nearest blocked cell above. That turns every row into a histogram, where the best rectangle is a bar's height times the gap between the nearest shorter bars on each side, and a monotonic stack finds those walls in one linear pass, for O(n·m) time and O(m) memory.