Back to course home
0% completed
Vote For New Content
Trapping Rain Water (hard)
Problem Statement
Given an array of positive integers height
, where height[i]
represents the height of the bar
in the elevation map
and each bar has width 1
, return how much water it can trap
after raining.
Examples
Example 1:
- Input: height =
[4, 0, 3, 0, 2]
- Expected Output:
5
- Justification: The first and third bars form a container that traps 3 units of water. The third and fifth bars trap an additional 2 units. Therefore, the total trapped water is 5 units.
Example 2:
- Input: height =
[1, 2, 1, 2, 1]
- **Expected Outpu
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page