Nonzero Local Maxima in Cornerless Neighborhoods
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