09 Sept 2026Go / Python / TypeScriptEasy

Projection Area of 3D Shapes

Compute the total area of a grid of cubes projected onto the three coordinate planes.

Count nonzero cells for the top view and add each row maximum and column maximum for the two side views.

complexity

O(n squared) time and O(1) extra space.

solution files

  • Go projection-area-of-3d-shapes/solution.go
  • Python projection-area-of-3d-shapes/solution.py
  • TypeScript projection-area-of-3d-shapes/solution.ts

Solution files

Goprojection-area-of-3d-shapes/solution.go
package main

func projectionArea(grid [][]int) int {
	area := 0
	for row := range grid {
		rowMax, columnMax := 0, 0
		for column := range grid {
			if grid[row][column] > 0 {
				area++
			}
			if grid[row][column] > rowMax {
				rowMax = grid[row][column]
			}
			if grid[column][row] > columnMax {
				columnMax = grid[column][row]
			}
		}
		area += rowMax + columnMax
	}
	return area
}
Pythonprojection-area-of-3d-shapes/solution.py
class Solution:
    def projectionArea(self, grid: list[list[int]]) -> int:
        top = sum(value > class="syntax-number">0 for row in grid for value in row)
        return top + sum(map(max, grid)) + sum(max(column) for column in zip(*grid))
TypeScriptprojection-area-of-3d-shapes/solution.ts
function projectionArea(grid: number[][]): number {
  let area = class="syntax-number">0;
  for (let row = class="syntax-number">0; row < grid.length; row += class="syntax-number">1) { let rowMax = class="syntax-number">0; let columnMax = class="syntax-number">0; for (let column = class="syntax-number">0; column < grid.length; column += class="syntax-number">1) { if (grid[row][column] > class="syntax-number">0) area += class="syntax-number">1; rowMax = Math.max(rowMax, grid[row][column]); columnMax = Math.max(columnMax, grid[column][row]); } area += rowMax + columnMax; }
  return area;
}