← All problems

Trapping Rain Water

HardTwo Pointers

Given an array of non-negative bar heights, compute how much water can be trapped after rain.

Examples

Input: [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6

Hints

Solution

Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 4 test cases.