• + 0 comments
    def surfaceArea(H,W,A):
        #top & bottom view sides
        top_bot=2*H*W
        ans=0
    		
        #row wise
        for row in A:
            ans+=row[0]+row[W-1] #right and left side of that row
            for i in range(W-1):
                ans+=abs(row[i]-row[i+1])
    						
        #col wise
        ans+=sum(A[0])+sum(A[H-1]) #top row side and bottom row side
        for i in range(H-1):
            for j in range(W):
                ans+=abs(A[i][j]-A[i+1][j])
                
        return ans + top_bot