S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Trapping Rainwater
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Hard
Array
Two Pointers
Stack
Dynamic Programming
Google
Amazon
Microsoft
Given elevation map as array, compute total rainwater trapped between bars after raining.
Examples
Example 1
Input →
[0,1,0,2,1,0,1,3,2,1,2,1]
Output →
6
Example 2
Input →
[4,2,0,3,2,5]
Output →
9
Example 3
Input →
[3,0,3]
Output →
3
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results