Surface Area of 3D Shapes Problem

Surface Area of 3D Shapes Problem — ExecCode Easy DSA Practice

Solve the Surface Area of 3D Shapes problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Your task is to compute the required answer and return the total surface area of the resulting shapes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j). After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes. Note: The bottom face of each shape counts toward its surface area.

Examples

Input {"grid": [[1, 2], [3, 4]]}; Output 34. Input {"grid": [[1, 1, 1], [1, 0, 1], [1, 1, 1]]}; Output 32

Constraints

n == grid.length == grid[i].length 1 <= n <= 50 0 <= grid[i][j] <= 50

Practice Surface Area of 3D Shapes free on ExecCode. Browse DSA problems, topic map, and placement guides.