Clear approach | Easy to undestand | C++
Code\n\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& A) {\n        int m = A.size(); //Num of columns\n        int n = A[0].si
# Code\n```\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& A) {\n        int m = A.size(); //Num of columns\n        int n = A[0].size(); //Num of rows\n        vector<vector<int>> left(m, vector<int>(n)), top(m, vector<int>(n));\n        for (int i = 0; i < m; ++i) {\n            for (int j = 0; j < n; ++j) {\n                left[i][j] = A[i][j] + (j && A[i][j] ? left[i][j - 1] : 0);\n                top[i][j] = A[i][j] + (i && A[i][j] ? top[i - 1][j] : 0);\n            }\n        }\n        for (int l = min(m, n); l > 0; --l) {\n            for (int i = 0; i < m - l + 1; ++i) {\n                for (int j = 0; j < n - l + 1; ++j) {\n                    if (min({\n                        top[i + l - 1][j], \n                        top[i + l - 1][j + l - 1], \n                        left[i][j + l - 1], \n                        left[i + l - 1][j + l - 1]\n                       }) >= l)\n                    return l * l;\n                }\n            }\n        }\n        return 0;\n    }\n};\n```
['C++']