← Visualizers
Partitioning & Window LeetCode 42

Trapping Rain Water / visualized

Water sitting above bar i is capped by min(leftMax, rightMax) - height[i]. The trick: whichever side has the smaller current wall is the side whose water level is already fully determined — move that pointer and settle its column immediately.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

leftMax line rightMax line trapped water
O(n) time · O(1) space  ·  no precomputed leftMax[]/rightMax[] arrays needed — the pointer choice guarantees the smaller max is already final.