✅✔️Easy and clean Implementation || C++ Solution ✈️✈️✈️✈️✈️
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n    void fillrd(int r, int c, vector<vector<int>>&rd, int n, int m, vector<vector<int>>& grid){\n        int rcnt = 0, ccnt = 0;\n        for(int j=c; j<m; j++){\n            if(grid[r][j] == 0) break;\n            rcnt++;\n        }\n        for(int i=r; i<n; i++){\n            if(grid[i][c] == 0) break;\n            ccnt++;\n        }\n        rd[r][c] = min(rcnt,ccnt);\n    }\n\n    void filllu(int r, int c, vector<vector<int>>&lu, int n, int m, vector<vector<int>>& grid){\n        int rcnt = 0, ccnt = 0;\n        for(int j=c; j>=0; j--){\n            if(grid[r][j] == 0) break;\n            rcnt++;\n        }\n        for(int i=r; i>=0; i--){\n            if(grid[i][c] == 0) break;\n            ccnt++;\n        }\n        lu[r][c] = min(rcnt,ccnt);\n    }\n\n    int solve(int r, int c, vector<vector<int>>&rd,vector<vector<int>>&lu){\n        for(int sz=rd[r][c]; sz>0; sz--){\n            if(lu[r+sz-1][c+sz-1] >= sz) return sz;\n        }\n        return 1;\n    }\n\n    int largest1BorderedSquare(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        vector<vector<int>>rd(n,vector<int>(m));\n        vector<vector<int>>lu(n,vector<int>(m));\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                fillrd(i,j,rd,n,m,grid);\n                filllu(i,j,lu,n,m,grid);\n            }\n        }\n        int ans = 0;\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(grid[i][j] == 1) ans = max(ans, solve(i,j,rd,lu));\n            }\n        }\n        return ans*ans;\n    }\n};\n```
['Array', 'Matrix', 'Prefix Sum', 'C++']