3567. Minimum Absolute Difference in Sliding Submatrix
You are given an
m x ninteger matrixgridand an integerk.For every contiguous
k x ksubmatrix ofgrid, compute the minimum absolute difference between any two distinct values within that submatrix.Return a 2D array
ansof size(m - k + 1) x (n - k + 1), whereans[i][j]is the minimum absolute difference in the submatrix whose top-left corner is(i, j)ingrid.Note: If all elements in the submatrix have the same value, the answer will be 0.
A submatrix
(x1, y1, x2, y2)is a matrix that is formed by choosing all cellsmatrix[x][y]wherex1 <= x <= x2andy1 <= y <= y2.
1 | class Solution { |