✅ C++ | ✅ 100% faster | Easy | Explained in comments.
\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        \n        // Thi
```\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        \n        // This will be our final matrix of size (n-2)*(n-2)\n        vector<vector<int>> ans(n-2,vector<int>(n-2));\n        \n        \n        /* We call our \'maxIn3x3\' function from index [(0,0) to (n-2,n-2)) excluding (n-2) i.e upto (n-3).\n\t\tWe will keep storing value returned by this function in \'ans\' array at corresponding (i,j) co-ordinate during loop traversal. */\n        for(int i=0;i<n-2;i++){\n            for(int j=0;j<n-2;j++)\n                ans[i][j] = maxIn3x3(grid, i, j);\n        }    \n        \n        // Happy return calculated ans matrix :)\n        return ans;\n    }\n    \n    \n    // A function that takes a starting cordinate (i,j) and returns max value in 3x3 size matrix starting from this cordinate.\n    int maxIn3x3(vector<vector<int>> &arr, int i, int j)\n\t{\n        int maxVal = INT_MIN;\n        \n        // Start from the index (i,j) and iterate for 3x3 matrix starting from this index and keep track of maximum value.\n        for(int x = i ; x < i+3 ; x++){\n            for(int y = j; y < j+3 ; y++)\n                maxVal = max(arr[x][y], maxVal);\n        }\n\n        // Happy return the maximum value of this 3x3 size matrix :)\n        return maxVal;\n    }\n    \n};\n```
['C', 'C++']