Fast and easy to understand solution - 2ms
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Calculates the size of the resulting box (excluding outer edges).\n2. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Calculates the size of the resulting box (excluding outer edges).\n2. Creates a new 2D array box to store the largest local values.\n3. Iterates through each cell of the box array:\n    * Calls maxValue to find the largest value within a 3x3 sub-grid around the current cell.\n    * Stores the returned maximum value in the corresponding cell of box.\n4. Returns the box array containing the largest local values.\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(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[][] largestLocal(int[][] grid) {\n        int size = grid.length-2;\n        int[][] box = new int[size][size];\n\n        for(int r=0; r<size; r++){\n            for(int c=0;c<size; c++){\n                box[r][c]= maxValue(grid,r,c);\n            }\n        }\n        return box;\n    }\n\n    public int maxValue(int[][] grid, int i, int j){\n\n        int max = 0;\n        for(int row=i; row<i+3; row++){\n            for(int col=j;col<j+3; col++){\n                max = Math.max(grid[row][col], max); \n            }\n        }\n        return max;\n    }\n}\n```
['Array', 'Math', 'Matrix', 'Java']