Example with multiple pits
Input
height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output
6
The elevation map traps 6 units of water in total.
Full lesson preview
Compute how much water can be trapped after raining given an elevation map using an optimal two-pointer method.
Problem statement
Task
Examples
Input
height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output
6
The elevation map traps 6 units of water in total.
Input format
Output format
Constraints
Samples
Input
[4,2,0,3,2,5]
Output
9
Classic example with total trapped water equal to 9.