Skip to content
6
0
:
0
0

Flood Pocket Counter: Canal Barrier Edition

Medium

Two Pointers

In "Flood Pocket Counter: Canal Barrier Edition", each number is the height of a wall with width 1.

Compute how many total units of rainwater are trapped after rainfall.

Example 1

Input:height = [0,4,1,4,0,1,2]
Output:6

For input height = [0,4,1,4,0,1,2], summing trapped water over each position gives 6. Therefore, return 6.

Example 2

Input:height = [4,2,0,2,3,0,2]
Output:7

For input height = [4,2,0,2,3,0,2], summing trapped water over each position gives 7. Therefore, return 7.

Constraints

  • 1 <= height.length <= 2 * 104
  • 0 <= height[i] <= 105
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[0,4,1,4,0,1,2]
Expected Output:
6
Test Case 2
Input:
[4,2,0,2,3,0,2]
Expected Output:
7