Easy C++ Solution
\n\n# Code\n\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& grid) \n    {\n        int n=grid.size();\n        int m=grid[0].si
\n\n# Code\n```\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& grid) \n    {\n        int n=grid.size();\n        int m=grid[0].size();\n        vector<vector<int>>hor(n,vector<int>(m,0));\n        vector<vector<int>>ver(n,vector<int>(m,0));\n        for (int i=0;i<n;i++)\n        {\n            int cnt=0;\n            for (int j=0;j<m;j++)\n            {\n              if (grid[i][j]==1)\n              {\n                  cnt++;\n                  hor[i][j]=cnt;\n              }\n              else cnt=0;\n            }\n        }\n        for (int j=0;j<m;j++)\n        {\n            int cnt=0;\n            for (int i=0;i<n;i++)\n            {\n                if (grid[i][j]==1)\n                {\n                    cnt++;\n                    ver[i][j]=cnt;\n                }\n                else cnt=0;\n            }\n        }\n       \n        int ans=0;\n        for (int i=0;i<n;i++)\n        {\n            for (int j=0;j<m;j++)\n            {\n                int sz=min(hor[i][j],ver[i][j]);\n                if (sz==0) continue;\n                for (int k=sz;k>ans;k--)\n                {\n                    if (hor[i-k+1][j]>=k && ver[i][j-k+1]>=k)\n                    {\n                        ans=max(ans,k);\n                    }\n                }\n            }\n        }\n        return ans*ans;\n    }\n};\n```
['C++']