3D Surface Area
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
LEARN BY DOINGPut your intuition to work3 steps
3D Surface Area
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Sample case — your program reads stdin and prints to stdout.
Starter 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 format
First line: H W (space-separated). Next H lines: W space-separated integers each.
Output format
A single integer: the total surface area.
Constraints
1 ≤ H, W ≤ 100, 0 ≤ A[i][j] ≤ 100