• + 0 comments

    my simple python sol

    def surfaceArea(A):
        cubemap = set()
        tot = 0
        for i in range(len(A)):
            for j in range(len(A[0])):
                for k in range(A[i][j]):
                    tot += 6
                    # check if any of the 6 adjacent spaces are occupied
                    # remove 2 for each shared face
                    cord = [i, j, k]
                    for a in range(3):
                        for b in range(-1, 2, 2):
                            cord[a] += b
                            if tuple(cord) in cubemap:
                                tot -= 2
                    cubemap.add((i, j, k))
        return tot