42. Trapping Rain Water

Practice Trapping Rain Water for free on NudgeCode: Hard, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

height describes a row of 1-unit-wide bars. After it rains, water collects in the dips between bars. Return the total units of water held.

Example

height = [0,1,0,2,1,0,1,3,2,1,2,1]  ->  6
height = [4,2,0,3,2,5]              ->  9

Constraints