dsa · hard
Trapping Rain Water
GreyOrangeArrayTwo PointersStack
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
Arguments
height— elevation map;height[i]is the height at index i
**Example 1:** `` Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 ` **Example 2:** ` Input: height = [4,2,0,3,2,5] Output: 9 ``
Constraints
1 <= height.length <= 2 * 10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [0,1,0,2,1,0,1,3,2,1,2,1] Expected: 6
Example 2
Input: [4,2,0,3,2,5] Expected: 9