Trapped rainwater

heights describes a row of walls. After rain, water sits wherever a lower wall has higher walls somewhere on both sides. Write trapped(heights) that returns the total units of water held.

trapped([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1])  ->  6
trapped([4, 2, 0, 3, 2, 5])                     ->  9
trapped([1, 2, 3])                              ->  0

The point is to practise two pointers where you can safely settle the lower side: the water above a position is bounded by the smaller of the tallest walls to its left and right.

def trapped(heights):
    ...