Java solution || simple || Easy to Understand || O(N^2) solution
The code aims to find the maximum order of the largest plus sign that can be formed in a grid of size n, while considering the presence of mines at certain posi
The code aims to find the maximum order of the largest plus sign that can be formed in a grid of size n, while considering the presence of mines at certain positions within the grid. The grid is represented by a 2D array where each cell initially contains a value of 1 (indicating no mine). Mines are represented by setting specific cells to 0.\n\nHere\'s a summary of the code:\n**Inner Class Total:**\n\nThis class represents the lengths of arms (left, right, up, down) for each cell in the grid.\nIt has four integer fields: l, r, u, d, representing the lengths of the left, right, up, and down arms respectively.\nThe constructor initializes these fields with the provided values.\n\n**orderOfLargestPlusSign Method:**\n\nThis method takes two parameters: n (an integer representing the size of the grid) and mine (a 2D array representing the positions of mines).\n\n**Initializing the Grid:**\n\nThe method initializes a 2D array called mines to represent the grid. Initially, all cells are set to 1, indicating no mines.\nIt uses Arrays.fill() method to initialize each row of the grid with 1s.\n\n**Setting Mines:**\n\nThe method iterates through the mine array, which contains the positions of mines, and sets the corresponding cells in the mines grid to 0, indicating the presence of a mine.\n\n**Initializing nums Array:**\n\nThe method initializes another 2D array called nums of type Total to store the lengths of arms for each cell.\nIt iterates through each cell of the grid and initializes the corresponding cell in the nums array with a new instance of the Total class, initializing all arm lengths to 0.\n\n**Calculating Arm Lengths:**\n\nThe method iterates through each row of the grid to calculate the lengths of the left and right arms for each cell.\nIt maintains a sum variable to keep track of the consecutive empty cells encountered (indicating the length of the arm).\nIf a mine is encountered, the sum is reset to 0, otherwise, it is incremented for each consecutive empty cell.\n\n**Similar Process for Columns:**\n\nThe method then repeats a similar process for columns to calculate the lengths of the up and down arms for each cell.\n\n**Finding Maximum Order:**\n\nOnce all arm lengths are calculated for each cell, the method iterates through the nums array to find the minimum of the lengths of all four arms for each cell.\nIt keeps track of the maximum of these minimums, which represents the order of the largest plus sign that can be formed.\n\n**Returning the Result:**\n\nFinally, the method returns the maximum order of the largest plus sign that can be formed considering the positions of mines.\n\n```\nclass Solution {\n    \n    public class Total {\n        int l;\n        int r;\n        int u;\n        int d;\n        \n        Total(int l, int r, int u, int d){\n            this.l = l;\n            this.r = r;\n            this.u = u;\n            this.d = d;\n        }\n    }\n    \n    public int orderOfLargestPlusSign(int n, int[][] mine) {\n        int[][] mines = new int[n][n];\n        \n        \n        for (int[] row : mines) {\n            Arrays.fill(row, 1);\n        }\n        \n        \n        for (int[] m : mine) {\n            mines[m[0]][m[1]] = 0;\n        }\n        \n        Total[][] nums = new Total[n][n];\n        \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                nums[i][j] = new Total(0, 0, 0, 0);\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = 0; j < n; j++) {\n                if (mines[i][j] == 0) {\n                    sum = 0;\n                    nums[i][j].l = sum;\n                } else {\n                    nums[i][j].l = ++sum;\n                }\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = n - 1; j >= 0; j--) {\n                if (mines[i][j] == 0) {\n                    sum = 0;\n                    nums[i][j].r = sum;\n                } else {\n                    nums[i][j].r = ++sum;\n                }\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = 0; j < n; j++) {\n                if (mines[j][i] == 0) {\n                    sum = 0;\n                    nums[j][i].u = sum;\n                } else {\n                    nums[j][i].u = ++sum;\n                }\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = n - 1; j >= 0; j--) {\n                if (mines[j][i] == 0) {\n                    sum = 0;\n                    nums[j][i].d = sum;\n                } else {\n                    nums[j][i].d = ++sum;\n                }\n            }\n        }\n        \n        int max = 0;\n        for (int i = 0; i < nums.length; i++) {\n            for (int j = 0; j < nums[0].length; j++) {\n                max = Math.max(Math.min(nums[i][j].l, Math.min(nums[i][j].r, Math.min(nums[i][j].d, nums[i][j].u))), max);\n            }\n        }\n        \n        return max;\n    }\n}\n\n```
['Array', 'Dynamic Programming', 'Java']