✅✅Faster || Easy To Understand || C++ Code
Dynamic Programming\n\n Time Complexity :- O(N * N)\n\n Space Complexity :- O(N * N)\n\n\nclass Solution {\npublic:\n    int orderOfLargestPlusSign(int n, vecto
* ***Dynamic Programming***\n\n* ***Time Complexity :- O(N * N)***\n\n* ***Space Complexity :- O(N * N)***\n\n```\nclass Solution {\npublic:\n    int orderOfLargestPlusSign(int n, vector<vector<int>>& mines) {\n        \n        vector<vector<int>> grid(n, vector<int> (n, 1));\n        \n        for(auto v : mines)\n        {\n            int x = v[0];\n            \n            int y = v[1];\n            \n            grid[x][y] = 0;\n        }\n        \n        // precalculate for left consecutive one\'s\n        \n        vector<vector<int>> left(n, vector<int> (n, 0));\n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = 0; j < n; j++)\n            {\n                if(j == 0)\n                {\n                    if(grid[i][j])\n                    {\n                        left[i][j] = 1;\n                    }\n                }\n                else\n                {\n                    if(grid[i][j])\n                    {\n                        left[i][j] = left[i][j - 1] + 1;\n                    }\n                    else\n                    {\n                        left[i][j] = 0;\n                    }\n                }\n            }\n        }\n        \n        // precalculate for right consecutive one\'s\n        \n        vector<vector<int>> right(n, vector<int> (n, 0));\n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = n - 1; j >= 0; j--)\n            {\n                if(j == n - 1)\n                {\n                    if(grid[i][j])\n                    {\n                        right[i][j] = 1;\n                    }\n                }\n                else\n                {\n                    if(grid[i][j])\n                    {\n                        right[i][j] = right[i][j + 1] + 1;\n                    }\n                    else\n                    {\n                        right[i][j] = 0;\n                    }\n                }\n            }\n        }\n        \n        // precalculate for top consecutive one\'s\n        \n        vector<vector<int>> top(n, vector<int> (n, 0));\n        \n        for(int j = 0; j < n; j++)\n        {\n            for(int i = 0; i < n; i++)\n            {\n                if(i == 0)\n                {\n                    if(grid[i][j])\n                    {\n                        top[i][j] = 1;\n                    }\n                }\n                else\n                {\n                    if(grid[i][j])\n                    {\n                        top[i][j] = top[i - 1][j] + 1;\n                    }\n                    else\n                    {\n                        top[i][j] = 0;\n                    }\n                }\n            }\n        }\n        \n        // precalculate for bottom consecutive one\'s\n        \n        vector<vector<int>> bottom(n, vector<int> (n, 0));\n        \n        for(int j = 0; j < n; j++)\n        {\n            for(int i = n - 1; i >= 0; i--)\n            {\n                if(i == n - 1)\n                {\n                    if(grid[i][j])\n                    {\n                        bottom[i][j] = 1;\n                    }\n                }\n                else\n                {\n                    if(grid[i][j])\n                    {\n                        bottom[i][j] = bottom[i + 1][j] + 1;\n                    }\n                    else\n                    {\n                        bottom[i][j] = 0;\n                    }\n                }\n            }\n        }\n        \n        // calculate maxi\n        \n        int maxi = 0;\n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = 0; j < n; j++)\n            {\n                if(grid[i][j])\n                {\n                    int left_co = left[i][j];\n                    \n                    int right_co = right[i][j];\n                    \n                    int top_co = top[i][j];\n                    \n                    int bottom_co = bottom[i][j];\n                \n                    int curr = min({top_co, bottom_co, left_co, right_co});\n                    \n                    maxi = max(maxi, curr);\n                }\n            }\n        }\n        \n        return maxi;\n    }\n};\n```
['Dynamic Programming', 'C', 'C++']