java simple solution commented step by step
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 {\n    public boolean check(int r,int c,int i,int j,int arr[][])\n    {\n        if(r>=arr.length||c>=arr[0].length)\n        {\n            return false;\n        } \n        // check col.. horizantal\n        for(int k=j;k<=Math.min(c,arr[0].length-1);k++)\n        {\n            if(arr[i][k]==0)\n            {\n                return false;\n            }\n        }\n        // check row vertical\n        for(int k=i;k<=Math.min(r,arr.length-1);k++)\n        {\n            if(arr[k][j]==0)\n            {\n                return false;\n            }\n        }\n        // check last row \n        for(int k=j;k<=Math.min(c,arr[0].length-1);k++)\n        {\n            if(arr[r][k]==0)\n            {\n                return false;\n            }\n        }\n        // check last col\n        for(int k=i;k<=Math.min(r,arr.length-1);k++)\n        {\n            if(arr[k][c]==0)\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n    public int largest1BorderedSquare(int[][] grid) {\n        int n=grid.length;\n        int m=grid[0].length;\n        int max=0;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                int curr_i=i;\n                int curr_j=j;\n                int ans=0;\n                int next_i=curr_i;\n                int next_j=curr_j;\n                for(int k=0;k<grid.length;k++)\n                {\n                    if(check(next_i,next_j,i,j,grid))\n                    {\n                        int area=k+1;\n                        max=Math.max(area*area,max);\n                    }\n                    next_i++;\n                    next_j++;\n                }  \n            }\n        } \n        // System.out.println(max);\n        return max;   \n    }\n}\n```
['Java']