Easy C++ Top Down DP Solution (Similar Problem)
Easy C++ Top Down DP Solution\n\nThis is very similar to the following problem:\n\nI. LC-1139\n\n\nclass Solution {\npublic:\n    int orderOfLargestPlusSign(int
**Easy C++ Top Down DP Solution**\n\nThis is very similar to the following problem:\n\nI. [LC-1139](https://leetcode.com/problems/largest-1-bordered-square/)\n\n```\nclass Solution {\npublic:\n    int orderOfLargestPlusSign(int N, vector<vector<int>>& mines) {\n        vector <vector<int>> hor(N, vector<int>(N, 1));\n        vector <vector<int>> ver(N, vector<int>(N, 0));\n        \n        for (auto mine : mines) {\n            hor[mine[0]][mine[1]] = 0;\n        }\n        \n        int maxAns = 0;\n        for (int i=0; i<N; i++) {\n            for (int j=0; j<N; j++) {\n                if (hor[i][j] == 1) {\n                    hor[i][j] = (j - 1 >= 0) ? hor[i][j - 1] + 1: 1;\n                    ver[i][j] = (i - 1 >= 0) ? ver[i - 1][j] + 1: 1;\n                }\n            }\n        }\n        \n        for (int i=0; i<N; i++) {\n            for (int j=0; j<N; j++) {\n                if (hor[i][j] > 0) {\n                    int val = min(hor[i][j], ver[i][j]);\n                    while (val > maxAns) {\n                        if ((j + val - 1 < N) && (i + val - 1 < N) && (hor[i][j + val - 1] >= val) && (ver[i + val - 1][j] >= val)) {\n                            maxAns = max(maxAns, val);\n                        }\n                        val--;\n                    }\n                }\n            }\n        }\n        \n        return maxAns;\n    }\n};\n```
['Dynamic Programming', 'C', 'C++']