FastPrepNonzero Local Maxima in Cornerless Neighborhoods

Nonzero Local Maxima in Cornerless Neighborhoods

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

For each nonzero cell, consider its in-bounds orthogonal neighbors—the centered 3 by 3 neighborhood with all four corners excluded. The cell is a local maximum when its value is strictly greater than every such neighbor.

Return zero-based [row,column] coordinates of all local maxima in row-major order. A nonzero cell with no orthogonal neighbor qualifies.

Function

cornerlessLocalMaxima(matrix: int[][]) → int[][]

Examples

Example 1

matrix = [[1,2,1],[2,9,2],[1,2,1]]return = [[1,1]]

The center exceeds all four orthogonal neighbors.

Example 2

matrix = [[5,5]]return = []

Strict comparison rejects both equal cells.

Constraints

  • 1 <= rows, columns <= 1000
  • -1000000000 <= matrix[r][c] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[][] cornerlessLocalMaxima(int[][] matrix) {
    // Write your code here.
}
matrix[[1,2,1],[2,9,2],[1,2,1]]
expected[[1,1]]
Checking account…