C++ DP Solution !!!
\n    int largest1BorderedSquare(vector<vector<int>>& g) {\n        int res = 0, cur = 0, m = g.size(), n = g[0].size();\n        vector<vector<int>> ver(m, vec
```\n    int largest1BorderedSquare(vector<vector<int>>& g) {\n        int res = 0, cur = 0, m = g.size(), n = g[0].size();\n        vector<vector<int>> ver(m, vector<int>(n, 0)),  hor(m, vector<int>(n, 0));\n        \n        for(int i = 0; i < m; i++) {\n            for(int j = 0; j < n; j++) {\n                if(g[i][j]) {\n                    ver[i][j] = 1 + (i == 0 ? 0 : ver[i-1][j]);\n                    hor[i][j] = 1 + (j == 0 ? 0 : hor[i][j-1]);\n                }\n            }\n        }\n        \n        for(int i = m-1; i >= 0; i--) {\n            for(int j = n-1; j >= 0; j--) {\n                int len = min(ver[i][j], hor[i][j]);\n                while(len > res) {\n                    if(ver[i][j-len+1] >= len && hor[i-len+1][j] >= len) {\n                        res = len;\n                        break;\n                    } else {\n                        len--;\n                    }\n                }\n            }\n        }\n        return res*res;\n    }\n```
[]