Easy C++ Constant Space Solution  | Beats 100 💯✅ | Max Pooling
Intuition\n Describe your first thoughts on how to solve this problem. \n- We start by traversing each cell in the grid.\n- For each cell, we consider its surro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We start by traversing each cell in the grid.\n- For each cell, we consider its surrounding cells (including diagonals) to find the maximum value.\n- Updating each cell\'s value in-place ensures that we maintain the largest local value for each cell.\n- Finally, we return the modified grid containing the largest local values for each cell.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Iterate through each cell of the grid.\n2. For each cell, iterate through its neighboring cells (up, down, left, right, and diagonals).\n3. Update the current cell\'s value to the maximum value among itself and its neighbors.\n4. Repeat steps 1-3 for all cells in the 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```\n#pragma GCC optimize("O3", "unroll-loops")\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        const int n=grid.size();\n        for(int i=1; i<n-1; i++){           \n            for(int j=1; j<n-1; j++){\n                for(int r=i-1; r<=i+1; r++)\n                    for( int c=j-1; c<=j+1; c++)\n                        grid[i-1][j-1]=max(grid[i-1][j-1], grid[r][c]);\n            }\n            grid[i-1].resize(n-2);\n        }\n        grid.resize(n-2);\n        return grid;\n    }\n};\n```
['Array', 'Math', 'Matrix', 'C++']