Two pointers walking inward, each capped by the tallest bar behind it. The shorter side is always safe to settle.
Water above a bar is capped by the shorter of the tallest wall to its left and the tallest wall to its right. Two pointers walking inward let you settle one bar per step without ever scanning for those walls.
water[i] = min(maxLeft[i], maxRight[i]) − height[i]. You never need the exact value of the taller side: if height[left] < height[right], then some bar at or right of `right` is at least as tall as height[right], so leftMax alone decides how much water sits on `left`. Settle that bar and move the pointer in.
On [0,1,0,2,1,0,1,3,2,1,2,1] the pointers start at 0 and 11. Each step compares the two ends, works the shorter one, and either raises that side's running max or banks the difference as water.
If height[left] < height[right], the wall on the right is already at least height[right] > height[left], so min(leftMax, rightMax) for index `left` can only be limited by leftMax. That is why one comparison is enough to commit a bar permanently. No backtracking, no second pass.
Each step retires exactly one index and the pointers only move inward, so the time is O(n). Only five scalars are kept and no prefix/suffix arrays are needed, so the space is O(1) (versus O(n) for the precomputed-maxima solution).
The same "advance the pointer that cannot be the bottleneck" argument powers Container With Most Water. The alternative DP solution precomputes prefix and suffix maxima in O(n) space; a monotonic stack solves it layer-by-layer instead of column-by-column.