def trapped_rain_water(arr):
    """
    For an array of positive numeric values, each element of the array represents
    the height of terrain capable of blocking water.
    :param arr: an array describing terrain height
    :return: the volume of water trapped within the terrain described by arr
    """
    larr = len(arr)
    volume = 0
    watermap = [0] * larr

    # initial pass, determine how much water can fill in from the left
    peak = 0
    for i in range(larr):
        # new or same peak, we are not adding water
        if peak <= arr[i]:
            peak = arr[i]
            continue

        # tentatively presume that the distance between the last peak and this height
        # is filled with water
        watermap[i] = peak - arr[i]

    # second pass, eliminate impossible amounts of water by finding right edges
    peak = 0
    for i in range(larr):
        # reverse the index
        i = larr - 1 - i

        # we found a new peak moving in reverse, this cell cannot add water
        if peak <= arr[i]:
            watermap[i] = 0
            peak = arr[i]
            continue

        # discover the cell's water level to the lesser of it's current water level (determined
        # by moving forward) or the current measured water level (determined by moving
        # in reverse) and add it to volume
        volume += min(watermap[i], peak - arr[i])

    return volume