2373. Largest Local Values in a Matrix

T: O(n^2)
S: O(n^2)
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)


 */

Last updated