Lesson 1 of 5
Live algorithm trace
Trapping rain with two sentinels
Complete execution1 of 12
Initialize both boundaries and both running maxima.
1
left = 0; right = length - 12
leftMax = rightMax = water = 03
resolve the side with the shorter current wall4
update that side's maximum5
add maximum - current height; move inward6
return waterleftMax = 0rightMax = 0water = 0
The final storm has arrived. Between these walls, rain collects wherever a shorter column is bounded by taller walls on both sides. Measure every trapped unit.