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