package com.fishercoder.solutions;

/**
 * 883. Projection Area of 3D Shapes
 *
 * On a N * N grid, we place some 1 * 1 * 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 grid cell (i, j).
 * Now 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.
 * Here, 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.
 *
 * Example 1:
 * Input: [[2]]
 * Output: 5
 *
 * Example 2:
 * Input: [[1,2],[3,4]]
 * Output: 17
 * Explanation:
 * Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
 *
 * Example 3:
 * Input: [[1,0],[0,2]]
 * Output: 8
 *
 * Example 4:
 * Input: [[1,1,1],[1,0,1],[1,1,1]]
 * Output: 14
 *
 * Example 5:
 * Input: [[2,2,2],[2,1,2],[2,2,2]]
 * Output: 21
 *
 * Note:
 * 1 <= grid.length = grid[0].length <= 50
 * 0 <= grid[i][j] <= 50
 * */
public class _883 {
    public static class Solution1 {
        /**credit: https://leetcode.com/problems/projection-area-of-3d-shapes/discuss/156726/C%2B%2BJavaPython-Straight-Forward-One-Pass*/
        public int projectionArea(int[][] grid) {
            int n = grid.length;
            int area = 0;
            for (int i = 0; i < n; i++) {
                int x = 0;
                int y = 0;
                for (int j = 0; j < n; j++) {
                    x = Math.max(x, grid[i][j]);
                    y = Math.max(x, grid[j][i]);
                    if (grid[i][j] > 0) {
                        area++;
                    }
                }
                area += x + y;
            }
            return area;
        }
    }
}

@@ -33,1055 +33,8 @@
 s;%0A%0A
-/**%0A * 883. Projection Area of 3D Shapes%0A *%0A * On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes.%0A * Each value v = grid%5Bi%5D%5Bj%5D represents a tower of v cubes placed on top of grid cell (i, j).%0A * Now we view the projection of these cubes onto the xy, yz, and zx planes.%0A * A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane.%0A * Here, we are viewing the %22shadow%22 when looking at the cubes from the top, the front, and the side.%0A * Return the total area of all three projections.%0A *%0A * Example 1:%0A * Input: %5B%5B2%5D%5D%0A * Output: 5%0A *%0A * Example 2:%0A * Input: %5B%5B1,2%5D,%5B3,4%5D%5D%0A * Output: 17%0A * Explanation:%0A * Here are the three projections (%22shadows%22) of the shape made with each axis-aligned plane.%0A *%0A * Example 3:%0A * Input: %5B%5B1,0%5D,%5B0,2%5D%5D%0A * Output: 8%0A *%0A * Example 4:%0A * Input: %5B%5B1,1,1%5D,%5B1,0,1%5D,%5B1,1,1%5D%5D%0A * Output: 14%0A *%0A * Example 5:%0A * Input: %5B%5B2,2,2%5D,%5B2,1,2%5D,%5B2,2,2%5D%5D%0A * Output: 21%0A *%0A * Note:%0A * 1 %3C= grid.length = grid%5B0%5D.length %3C= 50%0A * 0 %3C= grid%5Bi%5D%5Bj%5D %3C= 50%0A * */%0A
 publ
@@ -96,16 +96,28 @@
      /**
+%0A         * 
 credit: 
@@ -233,16 +233,26 @@
 One-Pass
+%0A         
 */%0A     

refactor 883