Given an array representing an elevation map, compute how much water it can trap after raining, using each bar's width as 1 unit.
Example 1
Explanation: Several small basins between taller bars trap a total of 6 units of water.
Example 2
Explanation: A monotonically increasing skyline has nothing taller to its left to trap water against, so no basin forms.
Example 3
Explanation: A monotonically decreasing skyline traps nothing, for the mirrored reason.
Could you compute the same answer using explicit left-max and right-max prefix arrays instead of two pointers, and what does that trade off in space?
Code execution is coming soon.