15. Trapping Rain Water

height is an elevation map where each bar has width 1. After it rains, how many units of water are trapped between the bars?

Example 1

Input: height = [3,0,2,0,4]
Output: 7
Explanation: Positions 1, 2 and 3 hold 3, 1 and 3 units.

Example 2

Input: height = [2,1,0,1,3]
Output: 4
Hint 1

Water above bar i = min(highest bar on its left, highest bar on its right) − height[i].

Hint 2

Two pointers: whichever side has the lower wall is already decided.

Two PointersStackDynamic Programming