Medium30 pts
3D Surface Area
2D grid A[i][j] = height (cubes) at cell (i,j). Calculate total surface area of the 3D shape. Formula: Top + Bottom + 4 sides. For each cell: top=1, bottom=1, each side = max(0, height - neighbor_height) if neighbor exists, else = height. Sum all faces. Example: Grid [[1,3,4],[2,2,3],[1,2,4]] → Calculate exposed faces for each cell and sum.
Input
First line: H W (space-separated). Next H lines: W space-separated integers each.
Output
A single integer: the total surface area.
Sample
3 3 1 3 4 2 2 3 1 2 4
Expected
60
Loading editor…
Output
No output yet. Run your code to see results.