Solutions for two-dimensional elevation

    • @MatthewIdete
    • @alexander, submitted in Python 3, achived 100% score
    def solve(walls):
        if len(walls) < 3:
            return 0
    
        total_water_volume = 0
    
        left = 0
        right = len(walls) - 1
        left_max = 0
        right_max = 0
    
        while left <= right:
            if walls[left] < walls[right]:
                if walls[left] > left_max:
                    left_max = walls[left]
                else:
                    total_water_volume += left_max - walls[left]
                left += 1
            else:
                if walls[right] > right_max:
                    right_max = walls[right]
                else:
                    total_water_volume += right_max - walls[right]
                right -= 1
    
        return total_water_volume