Trapping Rain Water
Bars of width 1 have heights . After rain, how much water is trapped between them?
Input
, then heights.
Output
Units of trapped water.
Constraints
,
Sample 1
Input
12 0 1 0 2 1 0 1 3 2 1 2 1
Output
6
Sample 2
Input
6 4 2 0 3 2 5
Output
9