✅ C++ |✅ Simple and Easy Solution|Beginner friendly
\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n       // Calculate the size of the modified grid\n       int k 
```\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n       // Calculate the size of the modified grid\n       int k = grid.size() - 2;\n       \n       // Initialize a new 2D vector \'arr\' with dimensions \'k\' x \'k\' and all elements set to 0\n       vector<vector<int>> arr(k, vector<int>(k, 0));\n       \n       // Iterate over the elements of \'arr\'\n       for(int i = 0; i < arr.size(); i++) {\n           for(int j = 0; j < arr.size(); j++) {\n               \n               // Find the maximum element within a 3x3 subgrid of \'grid\' starting at position (i, j)\n               int maxm = INT_MIN;\n               for(int p = i; p < i + 3; p++) {\n                   for(int q = j; q < j + 3; q++) {\n                       maxm = max(maxm, grid[p][q]);\n                   }\n               }\n               \n               // Assign the maximum value to the corresponding position in \'arr\'\n               arr[i][j] = maxm;\n           }\n       }\n             \n       // Return the modified grid\n       return arr;\n    }\n};\n```\n\n**Time Complexity:**\n\nThe outer two nested loops iterate arr.size() times, which is \'k\'. So, the time complexity of these loops is O(k^2).\nThe inner two nested loops iterate a constant number of times (3x3), so their time complexity is constant.\nOverall, the time complexity of the code is O(k^2) * O(1) = O(k^2).\n\n**Space Complexity:**\n\nThe space complexity is determined by the size of the arr vector, which is \'k\' x \'k\'.\nTherefore, the space complexity is O(k^2).\n
['C', 'Matrix']