> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/array_problem/2373.-largest-local-values-in-a-matrix.md).

# 2373. Largest Local Values in a Matrix

```
T: O(n^2)
S: O(n^2)
```

```java
class Solution {
    public int[][] largestLocal(int[][] grid) {
        int n = grid.length;
        int[][] result = new int[n-2][n-2];
        for (int sRow = 0; sRow < n - 2; sRow++) {
            for (int sCol = 0; sCol < n - 2; sCol++) {
                for (int i = sRow; i < sRow + 3; i++) {
                    for (int j = sCol; j < sCol + 3; j++) {
                        result[sRow][sCol] = Math.max(result[sRow][sCol], grid[i][j]);
                    }
                }
            }
        }
        return result;
    }
}
/***
T: O(n^2)
S: O(n^2)


 */
```
