Python O(n*3) solution
\ndef largest1BorderedSquare(self, g: List[List[int]]) -> int:\n        rows,cols = len(g), len(g[0])\n        a = [[0] * cols for _ in range(rows)]\n        a[
```\ndef largest1BorderedSquare(self, g: List[List[int]]) -> int:\n        rows,cols = len(g), len(g[0])\n        a = [[0] * cols for _ in range(rows)]\n        a[0][0] = [g[0][0] , g[0][0]]\n        for i in range(1, rows):\n            a[i][0] = [g[i][0], 0 if g[i][0] == 0 else a[i-1][0][1] + 1]\n        for j in range(1, cols):\n            a[0][j] = [0 if g[0][j] == 0 else a[0][j-1][0] + 1, g[0][j]]\n                    \n        res = max(0, sum(sum(g,[])) > 0)\n        for i in range(1, rows):\n            for j in range(1, cols):\n                a[i][j] = [0, 0]\n                if not g[i][j]: continue\n                    \n                a[i][j][0] = 0 if not g[i][j] else a[i][j-1][0] + 1\n                a[i][j][1] = 0 if not g[i][j] else a[i-1][j][1] + 1\n                \n                res = max(1, res)\n                for x in range(min(a[i][j][0], a[i][j][1])-1, 0, -1):\n                    if a[i][j-x][1] >= x+1 and a[i-x][j][0] >= x+1:\n                        res = max(res, x+1)\n                        break\n        return res * res\n```
[]