Find All Local Maximums
See the Image Source section at the very bottom of the page for the original problem statemetn :)
Given a matrix of integers, your task is to find all local maximums. An element is considered a local maximum if it is non-zero and no greater or equal elements exist within its defined region. The region for an element at matrix[i][j] is a square centered at (i, j) with a side length of (matrix[i][j] * 2 + 1), excluding the square's corners. For example, if matrix[2][2] is the element, the region would be a 5x5 square (as (matrix[2][2] * 2 + 1) equals 5), with only non-corner elements considered. If part of the region falls outside the matrix, only the portion within the matrix is evaluated. Your task is to return a 2D array containing the coordinates [row, col] of each local maximum, sorted first by row and then by column in case of ties. While an optimal solution isn’t required, the solution should have a time complexity no worse than O(matrix.length² * matrix[0].length²).
˚˖𓍢ִ໋🌷͙֒✧˚Endless thanks to Charlotte baby.🎀༘⋆C
1Example 1
