To solve this problem, you'll have to open it on the computer

Rain Water Harvesting

Arrays
hard
Score: 40

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can harvest after raining .

Input Format:

First Parameter - n , size of the array
Second Parameter - List of positive integer , height

Output Format:

Return the number

Example 1:

img

Input:
    n = 12
    height = [0 1 0 2 1 0 1 3 2 1 2 1]
Output:
     6
Explanation:
    The above elevation map (black section) is represented by array [0 1 0 2 1 0 1 3 2 1 2 1] . In this case, 6 units of rain water (blue section) are being harvested.

Example 2:

Input:
    n = 6
    height = [4 2 0 3 2 5]
Output:
    9

Constraints:

  • n == height.length
  • 1 <= n <= 2 * 104
  • 0 <= height[i] <=105
  • Expected Time Complexity: O(n)
  • Expected Space Complexity: O(n)
Submit code to see the your result here