🏆💢💯 Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅💥🔥💫Explained☠💥🔥 Beats 💯
Intuition\n\n\n\nC++ []\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        int n = grid.size();\n        vec
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/afc4374a-40f5-4d7f-b47f-b8873dbf0306_1715475852.6743572.jpeg)\n![Screenshot 2024-05-12 061822.png](https://assets.leetcode.com/users/images/2d76e395-a531-4e18-9203-ebb0052b05e5_1715475861.3593957.png)\n![Screenshot 2024-05-12 063343.png](https://assets.leetcode.com/users/images/8616df2b-d054-4633-a011-32d371ab105b_1715475868.4409828.png)\n```C++ []\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        int n = grid.size();\n        vector<vector<int>> v(n - 2, vector<int>(n - 2, 0));\n        for (int i = 1; i <= n - 2; i++) {\n            for (int j = 1; j <= n - 2; j++) {\n                int maxi = 0;\n                maxi = max({maxi, grid[i - 1][j - 1], grid[i - 1][j],\n                            grid[i - 1][j + 1]});\n                maxi = max({maxi, grid[i][j - 1], grid[i][j], grid[i][j + 1]});\n                maxi = max({maxi, grid[i + 1][j - 1], grid[i + 1][j],\n                            grid[i + 1][j + 1]});\n\n                v[i - 1][j - 1] = maxi;\n            }\n        }\n        return v;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:\n        n = len(grid)\n        ans = [[0] * (n - 2) for _ in range(n - 2)]\n        for i in range(n - 2):\n            for j in range(n - 2):\n                ans[i][j] = max(\n                    grid[ii][jj] for ii in range(i, i + 3) for jj in range(j, j + 3)\n                )\n        return ans\n```\n```C []\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume\n * caller calls free().\n */\nint** largestLocal(int** grid, int gridSize, int* gridColSize, int* returnSize, int** returnColumnSizes) {\n    int** arr = (int**)malloc((gridSize - 2) * sizeof(int*));\n    for (int i = 0; i < gridSize - 2; i++) {\n        arr[i] = (int*)malloc((gridSize - 2) * sizeof(int));\n    }\n    int arrSize = gridSize - 2;\n    *returnSize = arrSize;\n    for (int i = 0; i < arrSize; i++) {\n        for (int j = 0; j < arrSize; j++) {\n            arr[i][j] = maxElement(grid, i, j);\n        }\n    }\n    *returnColumnSizes = (int*)malloc(arrSize * sizeof(int));\n    for (int i = 0; i < arrSize; i++) {\n        (*returnColumnSizes)[i] = arrSize;\n    }\n    return arr;\n}\n\nint maxElement(int** grid, int r, int c) {\n    int max = INT_MIN;\n    for (int i = r; i < r + 3; i++) {\n        for (int j = c; j < c + 3; j++) {\n            max = fmax(grid[i][j], max);\n        }\n    }\n    return max;\n}\n```\n```Java []\nclass Solution {\n    public int[][] largestLocal(int[][] grid) {\n        int n = grid.length;\n        int[][] maxLocal = new int[n - 2][n - 2];\n        for (int i = 0; i < n - 2; ++i) {\n            for (int j = 0; j < n - 2; ++j) {\n                int max = 0;\n                for (int k = i; k < i + 3; ++k) {\n                    for (int l = j; l < j + 3; ++l) {\n                        max = Math.max(max, grid[k][l]);\n                    }\n                }\n                maxLocal[i][j] = max;\n            }\n        }\n\n        return maxLocal;\n    }\n}\n```\n```python []\nclass Solution(object):\n    def largestLocal(self, grid):\n        """\n        :type grid: List[List[int]]\n        :rtype: List[List[int]]\n        """\n        mtx = []\n        for i in range(len(grid) - 2):\n            mtx.append([])\n            for j in range(len(grid) - 2):\n                mtx[i].append(max(grid[i][j : j + 3] + grid[i + 1][j : j + 3] + grid[i + 2][j : j + 3]))\n        return mtx\n```\n\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    O(N^4)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)\n# Code\n```\nclass Solution(object):\n    def largestLocal(self, grid):\n        """\n        :type grid: List[List[int]]\n        :rtype: List[List[int]]\n        """\n        mtx = []\n        for i in range(len(grid) - 2):\n            mtx.append([])\n            for j in range(len(grid) - 2):\n                mtx[i].append(max(grid[i][j : j + 3] + grid[i + 1][j : j + 3] + grid[i + 2][j : j + 3]))\n        return mtx\n```\n# ***Please Upvote if it\'s useful for you...\n***![th.jpeg](https://assets.leetcode.com/users/images/b7025e28-1e9e-46df-96eb-8d3192f78a41_1715476016.8381047.jpeg)\n
['Array', 'C', 'Matrix', 'Python', 'C++', 'Java', 'Python3']