Problem
A list height describes an elevation map of bars, each one unit wide. After it rains, water settles in the dips between taller bars. Return how many units of water are trapped in total.
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
Example 3
- Input
- height = [3, 0, 3]
- Output
- 3
Aim for O(n) time and O(1) extra space.
Constraints
0 <= height.length <= 2 * 10^40 <= height[i] <= 10^5