#892
Surface Area of 3D Shapes
pupil · 345 · lc easy +22 · verified · 70.5% accepted · 611 likes · top 79%
Description
You are given an n x n grid where each cell (i, j) holds a tower of grid[i][j] unit cubes stacked vertically. Adjacent cubes (including between neighbouring towers) are fused together. Compute the total surface area of all resulting 3D shapes, counting every exposed face including the bottom.
Example 1:
Input: grid = [[1,2],[3,4]]
Output: 34
Example 2:
Input: grid = [[1,1,1],[1,0,1],[1,1,1]]
Output: 32
Example 3:
Input: grid = [[2,2,2],[2,1,2],[2,2,2]]
Output: 46
Code
1
2
3