Easy DFS solution using boolean grid and caching - with FULL explanation
Idea:\n Form a boolean matrix, indicating the positions of mines : matrix\n Form a Data class which has 4 integer values, representating number of consecutive 1
**Idea:**\n* Form a boolean matrix, indicating the positions of mines : `matrix`\n* Form a Data class which has 4 integer values, representating number of consecutive 1s in up, left, down and right directions\n* Form a matrix of Data type which will maintain cached values of number of 1s in all four directions for that particular position: `cache`\n* Start doing DFS for every position and fill out 4 values if not already filled out.\n* While doing DFS, keep the `cache` updated, so that one value for one cell is not calculated again through recursion.\n* After DFS completes, iterate over `cache` matrix, where we have number of consecutive `1`s in all 4 directions from that position, determine the largest square possible to form with that cell in the center, and maintain the max size of largest square in these loops.\n\n```\nclass Solution {\n    private enum Direction {\n        UP, LEFT, DOWN, RIGHT;\n    }\n    \n    private class Data {\n        int left, right, up, down;\n        Data(int left, int right, int up, int down) {\n            this.left = left;\n            this.right = right;\n            this.up = up;\n            this.down = down;\n        }\n    }\n    \n    public int orderOfLargestPlusSign(int N, int[][] mines) {\n        boolean[][] matrix = new boolean[N][N];\n        for (int[] mine : mines) {\n            matrix[mine[0]][mine[1]] = true;\n        }\n        \n        Data[][] cache = new Data[N][N];\n        \n        for (int i = 0; i < N; i++) {\n            for (int j = 0; j < N; j++) {\n                if (!matrix[i][j]) {\n                    dfs(matrix, cache, i, j);\n                }\n            }\n        }\n        \n        int ans = 0;\n        for (int i = 0; i < N; i++) {\n            for (int j = 0; j < N; j++) {\n                if (!matrix[i][j]) {\n                    Data cur = cache[i][j];\n                    ans = Math.max(ans,\n                                  Math.min(cur.up, Math.min(cur.left, Math.min(cur.down, cur.right))));\n                }\n            }\n        }\n        \n        return ans;\n        \n    }\n    \n    private void dfs(boolean[][] mines, Data[][] cache, int x, int y) {\n        if (cache[x][y] == null) {\n            cache[x][y] = new Data(-1, -1, -1, -1);\n        }\n        Data cur = cache[x][y];\n        cur.up = helper(mines, cache, x, y, Direction.UP);\n        cur.left = helper(mines, cache, x, y, Direction.LEFT);\n        cur.down = helper(mines, cache, x, y, Direction.DOWN);\n        cur.right = helper(mines, cache, x, y, Direction.RIGHT);\n    }\n    \n    private int helper(boolean[][] mines, Data[][] cache, int x, int y, Direction dir) {\n        if (!isValid(mines, x, y) || mines[x][y]) {\n            return 0;\n            \n        } \n        \n        if (cache[x][y] == null) {\n            cache[x][y] = new Data(-1, -1, -1, -1);\n        }\n        Data cur = cache[x][y];\n        \n        if (dir == Direction.UP) {\n            if (cur.up == -1) {\n                cur.up = 1 + helper(mines, cache, x-1, y, dir);\n            }\n            return cur.up;\n            \n        } else if (dir == Direction.LEFT) {\n            if (cur.left == -1) {\n                cur.left = 1 + helper(mines, cache, x, y-1, dir);\n            }\n            return cur.left;\n            \n        } else if (dir == Direction.DOWN) {\n            if (cur.down == -1) {\n                cur.down = 1 + helper(mines, cache, x + 1, y, dir);\n            }\n            return cur.down;\n            \n        } else if (dir == Direction.RIGHT) {\n            if (cur.right == -1) {\n                cur.right = 1 + helper(mines, cache, x, y+1, dir);\n            }\n            return cur.right;\n        }\n        \n        return -1; // should not reach here\n    }\n    \n    private boolean isValid(boolean[][] mines, int x, int y) {\n        return x >= 0 && x < mines.length && y >= 0 && y < mines[0].length;\n    }\n}\n```
[]