---
# System prepended metadata

title: 2373. Largest Local Values in a Matrix
tags: [Leetcode, Easy]

---

# 2373. Largest Local Values in a Matrix
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/largest-local-values-in-a-matrix/description/
## Code
```java=
class Solution {
    public int[][] largestLocal(int[][] grid) {
        int n = grid.length;
        int[][] ans = new int[n-2][n-2];
        for(int i=1; i<n-1; i++){
            for(int j=1; j<n-1; j++){
                ans[i-1][j-1] = grid[i][j];
                for(int x=i-1; x<=i+1; x++){
                    for(int y=j-1; y<=j+1; y++){
                        ans[i-1][j-1] = Math.max(ans[i-1][j-1], grid[x][y]);
                    }
                }
            }
        }
        return ans;
    }
}
```