Dynamic Programming
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 int largest1BorderedSquare(int[][] grid) {\n\n       int[][]hbox = new int [grid.length][grid[0].length];\n       int [][]vbox = new int [grid.length][grid[0].length];\n       for(int i = 0; i< grid.length; i++)\n       {\n        for(int j =0;j< grid[0].length;j++)\n        {\n        if(grid[i][j] == 1)\n        {\n            if(j>0){\n                hbox[i][j]= hbox[i][j-1];\n            }\n            if(i> 0)\n            {\n                vbox[i][j] = vbox[i-1][j];\n            \n            }\n            hbox[i][j] += 1;\n            vbox[i][j] += 1;\n        }\n       }\n       }\n       for(int[] a: hbox){\n        System.out.println(Arrays.toString(a));\n       }\n       System.out.println();\n       for(int[]a : vbox)\n       {\n        System.out.println(Arrays.toString(a));\n       }\n       int output =0;\n       for(int i = 0; i<grid.length; i++)\n       {\n        for(int j = 0; j< grid[0].length;j++)  \n       {\n        int size = Math.min(vbox[i][j],hbox[i][j]);\n        if(size == 0)continue;\n        for(int k = size; k > output; k--){\n\n         if(hbox[i-k+1][j]>= k && vbox[i][j-k+1]>= k)\n            {\n                output = Math.max(output,k);\n            }\n        }\n       }\n        }\nreturn output * output;\n    }\n\n}\n```
['Java']