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.

&nbsp;
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


&nbsp;
Constraints:


	n == grid.length == grid[i].length
	1 &lt;= n &lt;= 50
	0 &lt;= grid[i][j] &lt;= 50


class Solution:
    def projectionArea(self, grid: List[List[int]]) -> int:
        total = 0
		
        # top
        total += sum([1 for i in grid for j in i if j > 0])
        
		# front
        total +=  sum([max(col) for col in zip(*grid)])
        
		# side
        total +=  sum([max(row) for row in grid])
        
		return total
class Solution {
    public int projectionArea(int[][] grid) {
        int totalArea = 0;
        
        
        for(int[] row : grid){
            int max = row[0];
            for(int c : row){
                if(max < c){
                    max = c;
                }if(c != 0){
                    totalArea += 1;
                }
                
            }
            totalArea += max;
        }
        
        for(int c = 0; c < grid[0].length; c++){
            int max = grid[0][c];
            for(int row = 0; row  <  grid.length; row++){
                if(max < grid[row][c]){
                    
                    max = grid[row][c];
                }
            }
            totalArea += max;
            }
        return totalArea;
    }
}
class Solution {
public:
    int projectionArea(vector<vector<int>>& grid) {
        int res=0;
        // X-Y ( top )
        for(int i=0;i<grid.size();i++)
        {
            for(int j=0;j<grid[0].size();j++)
            {
                if(grid[i][j]) // if some cubes are present it is seen as of area 1 from top
                    res++; 
            }
        }
        
        // Z-X ( front )
        for(int i=0;i<grid.size();i++)
        {
            int m=grid[i][0];
            for(int j=1;j<grid[0].size();j++)
            {
                m=max(m,grid[i][j]);// from front, the tower with heightest height can only be seen in column
            }
            res+=m;
        }
        
        // Z-Y ( side )
        for(int j=0;j<grid[0].size();j++)
        {
            int m=grid[0][j];
            for(int i=1;i<grid.size();i++)
            {
                m=max(m,grid[i][j]);// // from side, the tower with heightest height can only be seen in row
            }
            res+=m;
        }
        return res;
    }
};
var projectionArea = function(grid) {
    let maxs = new Array(grid.length).fill(0);

    grid.forEach(row => row.forEach((val, idx) => {
        if (maxs[idx] < val) maxs[idx] = val;
    }))
    
    const z = grid.reduce((prev, curr) => prev + curr.filter(val => val !== 0).length, 0);
    const y = grid.reduce((prev, curr) => prev + Math.max(...curr), 0);
    const x = maxs.reduce((prev, curr) => prev + curr, 0)
    
    return x + y + z;
};
Projection Area of 3D Shapes