[JAVA] Brute Force Solution
\n    public int largest1BorderedSquare(int[][] grid) {\n        if (grid == null || grid.length == 0 || grid[0].length == 0) return 0;\n        int max = 0;\n 
```\n    public int largest1BorderedSquare(int[][] grid) {\n        if (grid == null || grid.length == 0 || grid[0].length == 0) return 0;\n        int max = 0;\n        int m = grid.length;\n        int n = grid[0].length;\n        for (int side = 1; side <= Math.min(m, n); side++) {\n            for (int i = 0; i <= m - side; i++) {\n                for (int j = 0; j <= n - side; j++) {\n                    if (max < side) {\n                        if (isValid(grid, i, j, side)) {\n                            max = side;\n                        }\n                    }\n                }\n            }\n        }\n        return max * max;\n    }\n    public boolean isValid(int[][] grid, int x, int y, int side) {\n        for (int i = x; i < x + side; i++) {\n            if (grid[i][y] != 1) return false;\n            if (grid[i][y + side - 1] != 1) return false;\n        }\n        for (int i = y; i < y + side; i++) {\n            if (grid[x][i] != 1) return false;\n            if (grid[x + side - 1][i] != 1) return false;\n        }\n        return true;\n    }\n```
[]