Trapping Rain Water

hard
1. Given n non-negative integers representing an elevation map where the width of each bar is 1.
2. Compute how much water it can trap after raining.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1. n == height.length
2. 0 <= n <= 3 * 10^4
3. 0 <= height[i] <= 10^5

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
12
0
1
0
2
1
0
1
3
2
1
2
1
Output
6
Previous
Maximal Rectangle
Next
Basic Calculator

Related Questions