Removing elements between the two zeros | Function to find the string after operation ; Travesing through string ; Checking for character Between two zeros ; Deleting the character At specific position ; Updating the length of the string ; Driver code
def findstring ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE s = list ( s ) NEW_LINE i = 1 NEW_LINE while i < n - 1 : NEW_LINE INDENT if ( s [ i - 1 ] == '0' and s [ i + 1 ] == '0' ) : NEW_LINE INDENT s . pop ( i ) NEW_LINE i -= 1 NEW_LINE if i > 0 and s [ i - 1 ] == '0' : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT n = len ( s ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return ' ' . join ( s ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( findstring ( '100100' ) ) NEW_LINE DEDENT