Sort by

recency

|

446 Discussions

|

  • + 0 comments

    Python3 Solution

    def surfaceArea(A):
        res = 0
        row = len(A)
        col = len(A[0])
        
        # calculate front and back
        for i in range(row):
            for j in range(col):
                if j != 0:
                    res += max(0, A[i][j]-A[i][j-1])
                else:
                    res += A[i][j]
                
                if j != col-1:
                    res += max(0, A[i][j]-A[i][j+1])
                else:
                    res += A[i][j]
                    
                if i != 0:
                    res += max(0, A[i][j]-A[i-1][j])
                else:
                    res += A[i][j]
                    
                if i != row-1:
                    res += max(0, A[i][j]-A[i+1][j])
                else:
                    res += A[i][j]
     
        res += 2*(row*col)       
        
        return res
    
  • + 0 comments

    I approached this problem counting surface from 4 directions: front, rear, left and right. Of course top and bottom are just HW. While thinking about it, perhaps you noticed that rather than 4 directions, we only need 2 by using the "abs" function, similar to how services for BMW Service Near Me optimize calculations to efficiently manage deliveries. Brilliant observation mate! So well done!

  • + 0 comments

    I approached this problem counting surface from 4 directions: front, rear, left and right. Of course top and bottom are just HW. While thinking about it, perhaps you noticed that rather than 4 directions, we only need 2 by using the "abs" function, similar to how services like adas calibration near me optimize calculations to efficiently manage deliveries. Brilliant observation mate! So well done!

  • + 0 comments

    Here is problem solution in python, java, c++, c and javascript programming - https://programmingoneonone.com/hackerrank-3d-surface-area-problem-solution.html

  • + 0 comments

    simulate putting each cube, for each cube, check 6 sides, if a cube exist on a side minus 2

    def surfaceArea(A):
        H = len(A)
        W = len(A[0])
        cubemap = set()
        tot = 0
    
        # Directions for 6 neighbors: (di, dj, dk)
        directions = [(1,0,0), (-1,0,0), (0,1,0), (0,-1,0), (0,0,1), (0,0,-1)]
    
        for i in range(H):
            for j in range(W):
                for k in range(A[i][j]):
                    tot += 6  # Each cube starts with 6 faces
                    # Check 6 neighbors
                    for di, dj, dk in directions:
                        ni, nj, nk = i + di, j + dj, k + dk
                        if (ni, nj, nk) in cubemap:
                            tot -= 2  # Shared face
                    cubemap.add((i, j, k))
    
        return tot