Trapping Rain Water
Given an array height representing an elevation map where each bar has width 1, compute how many units of water can be trapped between the bars after it rains.
Open official problem prompt ↗Total the rainwater that settles in the valleys of a bar-chart elevation map.
Two flood inspectors walk toward each other from opposite banks; the one on the lower embankment knows the water level over their spot is set by their own bank, so they measure and step inward.
- Input
- height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
- Output
- 6
- Why
- Water pools in the dips: summing trapped units across all positions gives 6 total.
n == height.length1 <= n <= 2 * 10^40 <= height[i] <= 10^5