Pre-Computation || Simple Solution || Commented
Complexity\n- Time complexity: O(mn) \n\n- Space complexity: O(mn) \n\n# Code\n\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& 
# Complexity\n- Time complexity: $$O(m*n)$$ \n\n- Space complexity: $$O(m*n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& grid) {\n        int side = 0;\n        vector<vector<int>> row = grid, col = grid;\n\n        for(int i=0; i<grid.size(); i++) {\n            for(int j=0; j<grid[0].size(); j++) {\n              //compute row-wise and col-wise prefix sum\n              if(grid[i][j] == 1) { \n                row[i][j] = (j > 0) ? 1 + row[i][j-1] : 1;\n                col[i][j] = (i > 0) ? 1 + col[i-1][j] : 1;\n              }\n              else { //if value in grid is 0, then its value in both row and col will be 0\n                row[i][j] = 0;\n                col[i][j] = 0;\n              }\n            }\n        }\n        for(int i=0; i<grid.size(); i++) {\n            for(int j=0; j<grid[0].size(); j++) {\n                int limit = min(row[i][j],col[i][j]);\n                //check for all possibilities of making a square\n                for(int mini=1; mini<=limit; mini++) {\n                    if(i-(mini-1) >= 0 && j-(mini-1) >= 0 && row[i-(mini-1)][j] >= mini && col[i][j-(mini-1)] >= mini) {\n                        side = max(side,mini); //update maximum possible side\n                    }\n                }\n            }\n        }\n     return side*side; //return it\'s area\n    }\n};\n```
['Dynamic Programming', 'Prefix Sum', 'C++']