Loop traversal to mark K adjacent positions to the left of already existing 1 s .
for i in range ( len ( s ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( s [ i ] == '1' ) : NEW_LINE INDENT for j in range ( i , - 1 , - 1 ) : NEW_LINE INDENT if ( j >= i - k ) : NEW_LINE INDENT ar [ j ] = - 1 NEW_LINE end = j NEW_LINE DEDENT DEDENT i = end NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE end = 0 NEW_LINE