• + 0 comments
    #python 3
    def surfaceArea(A):
        # Area of top, bottom, and front
        area = 2 * len(A[0]) * len(A) + sum(A[-1])
        for i, row in enumerate(A):
            #reset h for each row
            h = 0
            for j, stack in enumerate(row):
                #add left edge
                area += abs(stack - h)
                #add back edge
                area += abs(stack - (0 if i == 0 else A[i-1][j]))
                #update h to current stack
                h = stack
            #add right edge of final stack
            area += h
        return area