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.

  1. height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]

    expected = 6

  2. height = []

    expected = 0

  3. height = [0, 0, 0, 0]

    expected = 0

  4. height = [1, 2, 3, 4, 5]

    expected = 0

  5. height = [5, 4, 3, 2, 1]

    expected = 0

  6. height = [2, 0, 2]

    expected = 2

  7. height = [3, 0, 1, 3, 0, 5]

    expected = 8

  8. height = [4, 2, 0, 3, 2, 5]

    expected = 9

  9. height = [1, 0, 2, 1, 0, 1, 3]

    expected = 5

  10. height = [1]

    expected = 0

  11. height = [1, 2]

    expected = 0

  12. height = [2, 1, 2]

    expected = 1