Trapping Rain Water — highest walls on each side
Water above a bar is capped by the shorter of the tallest wall to its left and the tallest wall to its right. Precompute both, then each bar's water is that cap minus its own height.
Try:
← Prev
Next →
▶ Play
Reset
left_max
right_max
water trapped:
0