Concept Flow - Trapping Rain Water Using Stack
Start with empty stack
Iterate over height array
While stack not empty and current height > height at stack top
Pop top
Calculate distance and bounded height
Add trapped water
Push current index to stack
Repeat until end
Return total trapped water
We use a stack to keep indices of bars. When current bar is higher than stack top, we pop and calculate trapped water between bars.
