Flip the substrings of size K starting from i
for ( int j = i ; j < i + K ; j ++ ) { if ( S [ j ] == '1' ) S = S . Substring ( 0 , j ) + '0' + S . Substring ( j + 1 ) ; else S = S . Substring ( 0 , j ) + '1' + S . Substring ( j + 1 ) ; }