In a Meta-style coding interview, you are given an array height where each element represents the height of a vertical bar in an elevation map. Return the total amount of rain water that can be trapped after raining.
height, a list of non-negative integersWater above index i is determined by the shorter of the tallest bar to its left and right, minus height[i], if that value is positive.
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]6Example 2
height = [4,2,0,3,2,5]91 <= len(height) <= 2 * 10^40 <= height[i] <= 10^5Aim for a linear-time solution. A brute-force approach that scans left and right for every index is correct but too slow for large inputs.