Water at position equals . Instead of precomputing arrays, use two pointers with running maximums.
Track leftMax and rightMax as you go.
If leftMax < rightMax, process left pointer. Water is bounded by leftMax.
Otherwise process right pointer. Water is bounded by rightMax.
The smaller of the two maxes determines the water level at that position.