> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Projection Area of 3D Shapes Python Solution

> Tested Python solution for LeetCode 883 with 16 pytest cases. Generate a practice environment with lcpy.

LeetCode 883, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math), [Geometry](/catalog/topics/geometry), [Matrix](/catalog/topics/matrix). [View on LeetCode](https://leetcode.com/problems/projection-area-of-3d-shapes/description/).

Generate this problem as a practice environment: tested reference solution, 16 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 883   # by problem number
lcpy gen -s projection_area_of_3d_shapes   # by problem name
```

## Problem

You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.

Each value v = grid\[i]\[j] represents a tower of v cubes placed on top of the cell (i, j).

We view the projection of these cubes onto the xy, yz, and zx planes.

A projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

Return the total area of all three projections.

### Examples

![Example 1](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/02/shadow.png)

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

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

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

### Constraints

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

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/projection_area_of_3d_shapes/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/projection_area_of_3d_shapes/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n^2) over the grid cells
    # Space: O(1) extra beyond the input
    def projection_area(self, grid: list[list[int]]) -> int:
        top = sum(1 for row in grid for cube in row if cube > 0)
        front = sum(max(row) for row in grid)
        side = sum(max(col) for col in zip(*grid, strict=True))
        return top + front + side
```

## Complexity

| Time | Space |
| - | - |
| O(n^2) over the grid cells | O(1) extra beyond the input |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.