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