Python (Simple DP)
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    def largest1BorderedSquare(self, grid):\n        n, m = len(grid), len(grid[0])\n\n        top, left = [i[:] for i in grid], [i[:] for i in grid]\n\n        for i in range(n):\n            for j in range(m):\n                if grid[i][j] == 1:\n                    if i: top[i][j] = top[i-1][j] + 1\n                    if j: left[i][j] = left[i][j-1] + 1\n\n\n        for r in range(min(m,n),0,-1):\n            for i in range(n-r+1):\n                for j in range(m-r+1):\n                    if min(top[i+r-1][j],top[i+r-1][j+r-1],left[i][j+r-1],left[i+r-1][j+r-1]) >= r:\n                        return r*r\n\n        return 0\n\n\n        \n\n\n\n\n                \n\n\n\n\n\n\n        \n\n\n\n\n\n        \n\n        \n\n\n\n\n\n\n\n        \n\n\n\n```
['Python3']