Simple | O(n^2) | Just traverse in matrix and optimally stored values in answer vector | Refer Code
\n\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        int 
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        int m = grid[0].size();\n\n        vector<vector<int>> ans;\n\n        for(int i = 0 ; i < n-2 ; i++)\n        {\n            vector<int> temp;\n            for(int j = 0 ; j < m-2 ; j++)\n            {\n                int v1 = max({grid[i][j] , grid[i][j+1] , grid[i][j+2]});\n                int v2 = max({grid[i+1][j] , grid[i+1][j+1] , grid[i+1][j+2]});\n                int v3 = max({grid[i+2][j] , grid[i+2][j+1] , grid[i+2][j+2]});\n\n                int val = max({v1 , v2 , v3});\n\n                temp.push_back(val);\n            }\n            ans.push_back(temp);\n        }\n\n        return ans;\n    }\n};\n```
['Array', 'Matrix', 'C++']