Python Bruteforce O(N^4) Passed
Did not think it will pass, 1400 ms\n\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        \n        def checkOnes(r1,
Did not think it will pass, 1400 ms\n```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        \n        def checkOnes(r1, c1, r2, c2):\n            for i in range(c1, c2+1):\n                if grid[r1][i] == 0: return False\n            for i in range(c1, c2+1):\n                if grid[r2][i] == 0: return False\n            for j in range(r1, r2+1):\n                if grid[j][c1] == 0: return False\n            for j in range(r1, r2+1):\n                if grid[j][c2] == 0: return False   \n            return True\n        \n        count = 0\n        rowN, colN = len(grid), len(grid[0])\n        for r2 in range(rowN-1, -1, -1):\n            for c2 in range(colN-1, -1, -1):\n                shift = min(r2, c2)\n                for r1 in range(r2 - shift, r2+1):\n                    if count >= (r2 - r1 + 1)**2: break\n                    c1 = c2 - (r2 - r1)                         \n                    if checkOnes(r1, c1, r2, c2):\n                        # print(r1, c1, r2, c2)\n                        count = max(count, (r2 - r1 + 1)**2)\n                        break\n                            \n        return count\n```
[]