#883

Projection Area of 3D Shapes

newbie · 290 · lc easy +20 · verified · 75.7% accepted · 638 likes · top 87%

Description

You are given an n x n integer grid where grid[i][j] represents a tower of grid[i][j] unit cubes stacked at position (i, j).

Consider the shadow (projection) of the arrangement onto each of the three axis-aligned planes:

- The xy-plane (top-down view)

- The yz-plane (side view from the front)

- The zx-plane (side view from the right)

Return the combined total area of all three projections.

Example 1:

Input: grid = [[1,2],[3,4]]
Output: 17
Explanation: Here are the three projections ("shadows") of the shape made with each axis-aligned plane.

Example 2:

Input: grid = [[2]]
Output: 5

Example 3:

Input: grid = [[1,0],[0,2]]
Output: 8

Code

1
2
3