Pop a bar, measure its stretch
transcript
Buildings stand side by side. A banner must fit under the lowest roof it covers. A street can have a hundred thousand buildings. Which banner has the largest area?
Keep a stack of rising heights. It holds bar positions, not heights. A bar that is not higher pops the top. The entry below is the left edge. The arriving bar is the right edge.
Heights two, four, two, five, three. The second two pops the four. Width one. The three pops the five. Width one. A closing zero pops the rest. The last two spans five bars. Area ten.
Trying every pair of ends is slow. A hundred thousand bars need five billion checks. The stack pass pushes and pops each bar once.
Add a closing bar of height zero. Bars that only rise never pop alone. The closing bar pops them all.
Find both edges with one stack pass. Close the pass with a zero. Full breakdown in the lecture.