Back
Rain Water
Description
Fix the incorrect code to pass all the test cases.
You are given an array of non-negative integers height which represent an elevation map.
Each value height[i] represents the height of a bar, which has a width of 1.
Return the maximum area of water that can be trapped between the bars.
-
height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
expected = 6
-
height = []
expected = 0
-
height = [0, 0, 0, 0]
expected = 0
-
height = [1, 2, 3, 4, 5]
expected = 0
-
height = [5, 4, 3, 2, 1]
expected = 0
-
height = [2, 0, 2]
expected = 2
-
height = [3, 0, 1, 3, 0, 5]
expected = 8
-
height = [4, 2, 0, 3, 2, 5]
expected = 9
-
height = [1, 0, 2, 1, 0, 1, 3]
expected = 5
-
height = [1]
expected = 0
-
height = [1, 2]
expected = 0
-
height = [2, 1, 2]
expected = 1