Beginner-friendly Solution Using C++ || Clear
\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# 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```\nclass Solution {\npublic:\n    int largestValue(vector<vector<int>>& grid, int r, int c)\n    {\n        int maxValue = 0;\n        for (int i = r; i < r + 3; i++)\n        {\n            for (int j = c; j < c + 3; j++)\n            {\n                maxValue = max(maxValue, grid[i][j]);\n            }\n        }\n\n        return maxValue;\n    }\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\n        for (int i = 0; i < n - 2; i++) {\n            for (int j = 0; j < n - 2; j++)\n            {\n                ans[i][j] = largestValue(grid, i, j);\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']