java fast solution , iterating matrix only ONCE
You can calculate all the left,right,top,bottom in one matrix iteration.\n\nFirst init the grid as -2 to know we havent visited it yet. \nand keep the mines as 
You can calculate all the left,right,top,bottom in one matrix iteration.\n\nFirst init the grid as -2 to know we havent visited it yet. \nand keep the mines as -1 to make sure all the mines are marked ( eliminates the use of set and O(logn) factor for every iteration)\n\nif not visited then put the value as it is\nif visted then use the min of the left,right,top,bottom value or exisitng value\n\n```\nclass Solution {\n    public int orderOfLargestPlusSign(int n, int[][] mines) {\n        \n        \n        int dp[][] = new int[n][n];\n        \n        if(mines.length == dp.length*dp.length)\n            return 0;\n        \n        for(int i=0;i<dp.length;i++)\n            for(int j=0;j<dp.length;j++)\n                dp[i][j] = -2;\n        \n        for(int i=0;i<mines.length;i++){\n            dp[mines[i][0]][mines[i][1]] = -1;\n        }\n        \n        \n        \n        int left = 0;\n        int right =0;\n        int top = 0;\n        int bottom = 0;\n        \n        for(int i=0;i<dp.length;i++){\n            \n            for(int j=0;j<dp.length;j++) {\n                \n                if(dp[i][j] == -1) {\n                    left=0;\n                }\n                else {\n                    \n                    if(dp[i][j] == -2)\n                        dp[i][j] = left;\n                    else\n                    dp[i][j] = Math.min(dp[i][j],left);\n                    \n                    left++;\n                }\n                \n                if(dp[i][dp.length-j-1] == -1)\n                {\n                    right = 0;\n                }else\n                {\n                    if(dp[i][dp.length-j-1] == -2)\n                        dp[i][dp.length-j-1] = right;\n                    else\n                    dp[i][dp.length-j-1] = Math.min(dp[i][dp.length-j-1],right);\n                    \n                    right++;\n                }\n                \n                \n                if(dp[j][i] == -1)\n                {\n                    top = 0;\n                }else\n                {\n                    if(dp[j][i] == -2)\n                        dp[j][i] = top;\n                    else\n                    dp[j][i] = Math.min(dp[j][i],top);\n                    \n                    top++;\n                }\n                \n                \n                if(dp[dp.length-j-1][i] == -1)\n                {\n                    bottom = 0;\n                }else\n                {\n                    if(dp[dp.length-j-1][i] == -2)\n                        dp[dp.length-j-1][i] = bottom;\n                    else\n                    dp[dp.length-j-1][i] = Math.min(dp[dp.length-j-1][i],bottom);\n                    \n                    bottom++;\n                }\n                \n\n            }\n            \n            left=0;\n            right=0;\n            bottom=0;\n            top=0;\n        }\n        int max=0;\n        for(int i=0;i<dp.length;i++) {\n            \n            for(int j=0;j<dp.length;j++) {\n                \n            if(max<dp[i][j])\n                max = dp[i][j];\n                \n            }\n            \n        }\n        \n        \n        return max+1;\n        \n    }\n}\n\t```
[]