159. Rainwater Between Building Fronts
Hard
A street is represented by adjacent buildings, each with width 1. The alturas parameter contains the height of each building in order, and differences between those heights can form spaces where rainwater collects.
Return the total amount of water that can be trapped after the rain. Water can collect above a building only when there is a building at least as tall on each side; return an integer.
Example 1
Input: alturas = [0, 2, 0, 3]
Output: 2
Explanation: The space between the buildings of heights 2 and 3 traps two units of water.
Example 2
Input: alturas = [4, 1, 0, 2, 1, 5]
Output: 12
Explanation: The depressions between taller buildings hold a total of 12 units.
Example 3
Input: alturas = [5, 5, 5]
Output: 0
Explanation: Buildings of equal height leave no space for water to collect.
Constraints
- 0 <= alturas.length <= 20000
- 0 <= alturas[i] <= 100000
StackTwo pointersArrays
Saved in this browser
Caso 1
alturas =
[0,2,0,3]
Expected =
2
Caso 2
alturas =
[4,1,0,2,1,5]
Expected =
12
Caso 3
alturas =
[5,5,5]
Expected =
0
Run checks these 3 cases. Submit runs all 12, including hidden ones.