Create a capturing_rainwater() function that takes in an array of heights, and returns the amount of rainwater that could be contained in that array.

For example, the array [4, 2, 1, 3, 0, 1, 2] can be represented in the following histogram: Histogram with the Y-axis going from 0 to 4 and the X-axis containing the numbers from the array. Water is pooled in the empty spaces of the histogram, and you can see that it can contain 6 units of water. As you can see, there are 6 units of water that can be contained, so capturing_rainwater([4, 2, 1, 3, 0, 1, 2]) will return 6.

This challenge was reported to have been asked at interviews with many top companies, including Amazon and Microsoft. If you’ve covered the material in Pass the Technical Interview with Python or an equivalent, you should be able to solve this challenge. If you have trouble, try refreshing your knowledge with its Capturing Rainwater walkthrough.