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