Flip all the bits in this square sized submatrix
for ( let p = 0 ; p <= K - 1 ; p ++ ) { for ( let q = 0 ; q <= K - 1 ; q ++ ) { if ( a [ i + p ] [ j + q ] == ' ' ) { a [ i + p ] [ j + q ] = ' ' ; } else { a [ i + p ] [ j + q ] = ' ' ; } } } } } }