Java Easy to Understand Solution with Explanation || 100% beats
Intuition\n> The problem is straightforward. We iterate through maxLocal and check the 3x3 matrix windows.\n Describe your first thoughts on how to solve this p
# Intuition\n> The problem is straightforward. We iterate through `maxLocal` and check the 3x3 matrix windows.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. It initializes a new 2D array `maxLocal` with dimensions (size - 2) x (size - 2), where size is the size-2 of the input grid.\n2. It then iterates over the `maxLocal` grid using two nested loops(size - 2). These loops iterate over each position (i, j) in the input grid.\n3. For each position (i, j) in the input grid, it calls the `maxofMatric` method to find the maximum value in the 3x3 subgrid centered at (i, j).\n4. The maximum value found for each 3x3 subgrid is stored in the corresponding position (i, j) in the `maxLocal` array.\n5. Finally, it returns the `maxLocal` array containing the largest value in each 3x3 local region of the input grid.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O((n-2)\xB2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O((n-2)\xB2)$$\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;\n\n        int[][] maxLocal = new int[size - 2][size - 2];\n\n        for (int i = 0; i < size - 2; i++) {\n            for (int j = 0; j < size - 2; j++) {\n                maxLocal[i][j] = maxofMatric(grid, i, j);\n            }\n        }\n\n        return maxLocal;\n    }\n\n    public int maxofMatric(int[][] grid, int temp1, int temp2) {\n        int max = 0;\n\n        for (int i = temp1; i < temp1 + 3; i++) {\n            for (int j = temp2; j < temp2 + 3; j++) {\n                max = Math.max(max, grid[i][j]);\n            }\n        }\n\n        return max;\n    }\n}\n```\n\n![image.png](https://assets.leetcode.com/users/images/4d2bcf88-5377-4274-9684-84e188e6a6ca_1715497308.6169095.png)\n
['Java']