C++ DP solution
\n    int largest1BorderedSquare(vector>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        vector>> dp (n, vector> (m, vector (2, 0))
\n    int largest1BorderedSquare(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        vector<vector<vector<int>>> dp (n, vector<vector<int>> (m, vector<int> (2, 0)));\n        for(int i=0;i<dp.size();i++)\n        {\n            for(int j=0;j<dp[0].size();j++)\n            {\n                if(grid[i][j]==1)\n                {\n                    if(i==0 && j==0)\n                    {\n                                            dp[i][j][0]=1;\n                    dp[i][j][1]=1;\n                        \n                    }\n                    else if(i==0)\n                    {\n                        dp[i][j][0]=1;\n                        dp[i][j][1]=dp[i][j-1][1]+1;\n                        \n                    }\n                    else if(j==0)\n                    {\n                        dp[i][j][0]=dp[i-1][j][0]+1;\n                        dp[i][j][1]=1;\n                    }\n                    else\n                    {\n                        dp[i][j][0]=dp[i-1][j][0]+1;\n                        dp[i][j][1]=dp[i][j-1][1]+1;\n                        \n                    }\n                    \n\n                    \n                }\n            }\n        }\n        \n        int ans=0;\n        for(int i=dp.size()-1;i>=0;i--)\n        {\n            for(int j=dp[0].size()-1;j>=0;j--)\n            {\n                int mini=min(dp[i][j][0],dp[i][j][1]);\n             int k=mini;\n                \n                for(k=mini;k>=1;k--)\n                {\n                    if(dp[i][j-k+1][0]>=k && dp[i-k+1][j][1]>=k)\n                    {\n                        break;\n                        \n                    }\n                }\n                ans=max(ans,k);        \n            }\n        }\n        \n        return ans*ans;\n        \n        \n    }\n
['Dynamic Programming']