Java/C++/Python O(N^2) solution using only one grid matrix
Algorithms: For each position (i, j) of the grid matrix, we try to extend in each of the four directions (left, right, up, down) as long as possible, then take 
**Algorithms**: For each position `(i, j)` of the `grid` matrix, we try to extend in each of the four directions (left, right, up, down) as long as possible, then take the minimum length of `1`\'s out of the four directions as the order of the largest axis-aligned plus sign centered at position `(i, j)`.\n\n---\n\n**Optimizations**: Normally we would need a total of five matrices to make the above idea work -- one matrix for the `grid` itself and four more matrices for each of the four directions. However, these five matrices can be combined into one using two simple tricks:\n\n1. For each position `(i, j)`, we are only concerned with the minimum length of `1`\'s out of the four directions. This implies we may combine the four matrices into one by only keeping track of the minimum length.\n\n2. For each position `(i, j)`, the order of the largest axis-aligned plus sign centered at it will be `0` if and only if `grid[i][j] == 0`. This implies we may further combine the `grid` matrix with the one obtained above.\n\n---\n\n**Implementations**:\n\n1. Create an `N-by-N` matrix `grid`, with all elements initialized with value `N`.\n2. Reset those elements to `0` whose positions are in the `mines` list.\n3. For each position `(i, j)`, find the maximum length of `1`\'s in each of the four directions and set `grid[i][j]` to the minimum of these four lengths. Note that there is a simple recurrence relation relating the maximum length of `1`\'s at current position with previous position for each of the four directions (labeled as `l`, `r`, `u`, `d`).\n4. Loop through the `grid` matrix and choose the maximum element which will be the largest axis-aligned plus sign of `1`\'s contained in the grid.\n\n---\n\n**Solutions**: Here is a list of solutions for Java/C++/Python based on the above ideas. All solutions run at `O(N^2)` time with `O(N^2)` extra space. Further optimizations are possible such as keeping track of the maximum plus sign currently available and terminating as early as possible if no larger plus sign can be found for current row/column.\n\n**Note**: For those of you who got confused by the logic within the first nested for-loop, refer to [andier\'s comment](https://leetcode.com/problems/largest-plus-sign/discuss/113314/JavaC++Python-O(N2)-solution-using-only-one-grid-matrix/114381) and [my comment](https://leetcode.com/problems/largest-plus-sign/discuss/113314/JavaC++Python-O(N2)-solution-using-only-one-grid-matrix/114382) below for a more clear explanation.\n\n**Java solution:**\n\n```\npublic int orderOfLargestPlusSign(int N, int[][] mines) {\n    int[][] grid = new int[N][N];\n        \n    for (int i = 0; i < N; i++) {\n        Arrays.fill(grid[i], N);\n    }\n        \n    for (int[] m : mines) {\n        grid[m[0]][m[1]] = 0;\n    }\n        \n    for (int i = 0; i < N; i++) {\n        for (int j = 0, k = N - 1, l = 0, r = 0, u = 0, d = 0; j < N; j++, k--) {\n            grid[i][j] = Math.min(grid[i][j], l = (grid[i][j] == 0 ? 0 : l + 1));  // left direction\n            grid[i][k] = Math.min(grid[i][k], r = (grid[i][k] == 0 ? 0 : r + 1));  // right direction\n            grid[j][i] = Math.min(grid[j][i], u = (grid[j][i] == 0 ? 0 : u + 1));  // up direction\n            grid[k][i] = Math.min(grid[k][i], d = (grid[k][i] == 0 ? 0 : d + 1));  // down direction\n        }\n    }\n        \n    int res = 0;\n        \n    for (int i = 0; i < N; i++) {\n        for (int j = 0; j < N; j++) {\n            res = Math.max(res, grid[i][j]);\n        }\n    }\n        \n    return res;\n}\n```\n\n<br>\n\n**C++ solution:**\n\n```\nint orderOfLargestPlusSign(int N, vector<vector<int>>& mines) {\n    vector<vector<int>> grid(N, vector<int>(N, N));\n        \n    for (auto& m : mines) {\n        grid[m[0]][m[1]] = 0;\n    }\n        \n    for (int i = 0; i < N; i++) {\n        for (int j = 0, k = N - 1, l = 0, r = 0, u = 0, d = 0; j < N; j++, k--) {\n            grid[i][j] = min(grid[i][j], l = (grid[i][j] == 0 ? 0 : l + 1));\n            grid[i][k] = min(grid[i][k], r = (grid[i][k] == 0 ? 0 : r + 1));\n            grid[j][i] = min(grid[j][i], u = (grid[j][i] == 0 ? 0 : u + 1));\n            grid[k][i] = min(grid[k][i], d = (grid[k][i] == 0 ? 0 : d + 1));\n        }\n    }\n        \n    int res = 0;\n        \n    for (int i = 0; i < N; i++) {\n        for (int j = 0; j < N; j++) {\n            res = max(res, grid[i][j]);\n        }\n    }\n        \n    return res;\n}\n```\n\n<br>\n\n**Python solution:**\n\n```\ndef orderOfLargestPlusSign(self, N, mines):\n    """\n    :type N: int\n    :type mines: List[List[int]]\n    :rtype: int\n    """\n    grid = [[N] * N for i in range(N)]\n        \n    for m in mines:\n        grid[m[0]][m[1]] = 0\n            \n    for i in range(N):\n        l, r, u, d = 0, 0, 0, 0\n            \n        for j, k in zip(range(N), reversed(range(N))):\n            l = l + 1 if grid[i][j] != 0 else 0\n            if l < grid[i][j]:\n                grid[i][j] = l\n            \n            r = r + 1 if grid[i][k] != 0 else 0\n            if r < grid[i][k]:\n                grid[i][k] = r\n\n            u = u + 1 if grid[j][i] != 0 else 0\n            if u < grid[j][i]:\n                grid[j][i] = u\n                \n            d = d + 1 if grid[k][i] != 0 else 0\n            if d < grid[k][i]:\n                grid[k][i] = d\n        \n    res = 0\n        \n    for i in range(N):\n        for j in range(N):\n            if res < grid[i][j]:\n                res = grid[i][j]\n                \n    return res\n```
[]