Update the minimum column - wise
for ( let j = 0 ; j < M ; j ++ ) { for ( let i = 0 ; i < N - K + 1 ; i ++ ) { let min = Number . MAX_VALUE ; for ( let k = i ; k < i + K ; k ++ ) { min = Math . min ( min , nums [ k ] [ j ] ) ; } nums [ i ] [ j ] = min ; } }