C++ solution | 2 simple ways
Method -> 1\n\nclass Solution {\nprivate:\n    int giveMax(vector<vector<int>>& v,int i,int j){\n        return max({v[i][j],v[i+1][j],v[i+2][j],v[i][j+1],v[i+1
**Method -> 1**\n```\nclass Solution {\nprivate:\n    int giveMax(vector<vector<int>>& v,int i,int j){\n        return max({v[i][j],v[i+1][j],v[i+2][j],v[i][j+1],v[i+1][j+1],v[i+2][j+1],v[i][j+2],v[i+1][j+2],v[i+2][j+2]});\n    }\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        int n = grid.size();\n        vector<vector<int>> ans(n-2,vector<int>(n-2));\n        for(int i=0; i<n-2; ++i){\n            for(int j=0; j<n-2; ++j){\n                ans[i][j] = giveMax(grid,i,j);\n            }\n        }\n        return ans;\n    }\n};\n```\n**Method -> 2**\n```\nclass Solution {\nprivate:\n    vector<pair<int,int>> movements {{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1},{2,2}};\n    int giveMax(vector<vector<int>>& v,int i,int j){\n        int mx = INT_MIN;\n        for(auto [x,y]: movements)\n            mx = max(mx,v[x+i][y+j]);\n        return mx;\n    }\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        int n = grid.size();\n        vector<vector<int>> ans(n-2,vector<int>(n-2));\n        for(int i=0; i<n-2; ++i){\n            for(int j=0; j<n-2; ++j){\n                ans[i][j] = giveMax(grid,i,j);\n            }\n        }\n        return ans;\n    }\n};\n```
[]