[Python] Time O(n*m*min(n, m)), Space O(n*m), DP Super Concise but Easy to Understand
\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        left = [[0 for _ in range(len(grid[0]))] for _ in range(len(grid
```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        left = [[0 for _ in range(len(grid[0]))] for _ in range(len(grid))]\n        top = [[0 for _ in range(len(grid[0]))] for _ in range(len(grid))]\n        \n        max_side = 0\n        for i in range(len(grid)):\n            for j in range(len(grid[0])):\n                top[i][j] = top[i-1][j]+1 if i>0 and grid[i][j] else grid[i][j]\n                left[i][j] = left[i][j-1]+1 if j>0 and grid[i][j] else grid[i][j]\n                for side in range(min(top[i][j], left[i][j]), max_side, -1):\n                    if left[i-side+1][j] >= side and top[i][j-side+1] >= side:\n                        max_side = side\n        return max_side**2\n```
[]