92% FASTER || BOTTOM-UP DP || count row, col
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: List[List[int]]) -> int:\n\n        m, n = len(grid), len(grid[0])\n        res = 0\n        col = [[0]*(n+1) for _ in range(m+1)]\n        row = [[0]*(n+1) for _ in range(m+1)]\n\n        for i in range(1, m+1):\n            for j in range(1, n+1):\n                if grid[i-1][j-1] != 0:\n                    row[i][j] = row[i-1][j] + 1\n                    col[i][j] = col[i][j-1] + 1\n                    \n\n                    x = min(col[i][j], row[i][j])\n                    \n                    for k in range(x, res, -1):\n                        if k <= min(col[i-k+1][j], row[i][j-k+1]):\n                            res = max(1, res, k)\n        \n       \n                    \n        \n        return res**2\n\n```
['Python3']