Python 3 | Prefix-sum, DP, O(N^3) | Explanation
Implementation as hint section suggested\n- See below comments for more detail\n\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -
- Implementation as __*hint*__ section suggested\n- See below comments for more detail\n```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        m, n = len(grid), len(grid[0])\n        dp = [[(0, 0)] * (n) for _ in range((m))] \n        for i in range(m):                      # calculate prefix-sum as `hint` section suggested\n            for j in range(n):\n                if not grid[i][j]:\n                    continue\n                dp[i][j] = (dp[i][j][0] + dp[i-1][j][0] + 1, dp[i][j][1] + dp[i][j-1][1] + 1)\n        for win in range(min(m, n)-1, -1, -1):  # for each window size\n            for i in range(m-win):              # for each x-axis\n                for j in range(n-win):          # for each y-axis\n                    if not grid[i][j]: continue # determine whether square of (i, j), (i+win, j+win) is 1-boarded\n                    x1, y1 = dp[i+win][j+win]   # bottom-right corner\n                    x2, y2 = dp[i][j+win]       # upper-right corner\n                    x3, y3 = dp[i+win][j]       # bottom-left corner\n                    x4, y4 = dp[i][j]           # upper-left corner\n                    if y1 - y3 == x1 - x2 == y2 - y4 == x3 - x4 == win:\n                        return (win+1) * (win+1)\n        return 0\n```
['Dynamic Programming', 'Matrix', 'Python', 'Python3']