Loop traversal to mark K adjacent positions to the right of already existing 1 s .
for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] == '1' ) { for ( int j = i ; j < s . length ( ) && j <= i + k ; j ++ ) { ar [ j ] = -1 ; end = j ; } i = end ; } } end = 0 ;