n × n pad holds towers of identical unit cubes: heights[i][j] is how many cubes are stacked in cell (i, j). Zero means the cell is empty.
Shine a light on the structure from above, from the front (along the rows) and from the side (along the columns), and three shadows appear on three perpendicular walls. Each shadow is made of unit squares.
Return the combined area of all three shadows.heights=[[3, 0], [1, 2]] → 13
From above, 3 cells hold cubes. From the front you see the row maxima: 3 + 2 = 5. From the side, the column maxima: 3 + 2 = 5. Total: 3 + 5 + 5 = 13.
heights=[[4]] → 9
A single tower of height 4: 1 from above, 4 from the front, 4 from the side.
heights=[[0, 0], [0, 0]] → 0
No cubes, no shadows.
heights=[[3, 0], [1, 2]]
13
Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.