Goldman Sachs interview question

Trapping rainwater. Leetcode hard question