hard
Trapping Rain Water
Given an elevation map as an array of non-negative bar heights (each of width one), compute how much water is trapped between the bars after rain.
Constraints
- 1 ≤ n ≤ 2 · 10^4
- 0 ≤ height[i] ≤ 10^5
Examples
in: height = [0,1,0,2,1,0,1,3,2,1,2,1]
out: 6
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.