Skip to content

Practice Largest Local Values in a Matrix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2373
LeetCode Problem

Largest Local Values in a Matrix

Problem Statement

For every 3 by 3 contiguous window in the n by n grid, compute its largest value. Return an (n - 2) by (n - 2) matrix whose entry [i][j] is the maximum over rows i through i + 2 and columns j through j + 2.

Source: Largest Local Values in a Matrix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
Output
[[9,9],[8,6]]

# Example 2

Input
grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
Output
[[2,2,2],[2,2,2],[2,2,2]]

Constraints

n == grid.length == grid[i].length
3 <= n <= 100
1 <= grid[i][j] <= 100

Related LeetCode Problems

Practice more problems similar to Largest Local Values in a Matrix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.