[Python3] Dynamic programming solution
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n> O(MN * min(M\N))\n- Space complexity:\n Add your space complexity here, e.g. O(n) 
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n> O(M*N * min(M\\*N))\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n> O(M*N)\n# Code\n```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        m, n = len(grid), len(grid[0])\n        Table = [[[0,0] for _ in range(n)] for _ in range(m)]\n        ans = 0\n        for i in range(m-1, -1, -1):\n            for j in range(n-1, -1, -1):\n                if grid[i][j]:\n                    Table[i][j][0] = 1 + (Table[i][j+1][0] if j+1<n and grid[i][j+1] else 0)\n                    Table[i][j][1] = 1 + (Table[i+1][j][1] if i+1<m and grid[i+1][j] else 0)\n                    for s in range(min(Table[i][j][0],Table[i][j][1]), -1 ,-1):\n                        if Table[i][j+s-1][1] >= s and Table[i+s-1][j][0] >= s:\n                            ans = max(ans, s)\n                            break\n        return ans**2\n```
['Dynamic Programming', 'Python3']