Python Super Simple O(1), O(N^2) solution with a sprinkle of DP
Intuition\nI recommend to check the code while reading the explanaition. This is a problem where the code explains itself better than comments.\n\n Describe you
# Intuition\nI recommend to check the code while reading the explanaition. This is a problem where the code explains itself better than comments.\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using a little of Dynamic Programming:** \nBrute force would be to compute 3x3 matrix every time. However we don\'t need to do it every time.  Instead compute 3x1 columns and remember last 3 columns. \n\nThis way you will beat 95% of python users.\n\n**Saving result in grid:**  \nSay current indices are `i, j`. Then, once maximum of 3 columns is computed it can be stored at `grid[i][j] ` because we will never need `grid[i][j]` in future.\n\nWhat is left is to pop 2 elements in the end of each row of `grid[i]`. And to pop 2 rows in the end of `grid`.\n\n# Complexity\n- Time complexity: O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:\n\n        N = len(grid)\n        for i in range(N - 2):\n            for j in range(N - 2):\n                if j == 0:\n                    maxFirst = max(grid[i][j], grid[i + 1][j], grid[i + 2][j])\n                    maxSecond = max(grid[i][j + 1], grid[i + 1][j + 1], grid[i + 2][j + 1])\n                    maxThird = max(grid[i][j + 2], grid[i + 1][j + 2], grid[i + 2][j + 2])\n                else:\n                    maxNext = max(grid[i][j + 2], grid[i + 1][j + 2], grid[i + 2][j + 2])\n                    maxFirst, maxSecond, maxThird = maxSecond, maxThird, maxNext\n\n                grid[i][j] = max(maxFirst, maxSecond, maxThird)\n                \n            grid[i].pop()\n            grid[i].pop()\n\n        grid.pop()\n        grid.pop()\n                \n\n        return grid\n     \n```
['Python3']