Print string after removing all ( “ 10 ” or “ 01 ” ) from the binary string | Function to print the final string after removing all the occurrences of "10" and "01" from the given binary string ; Variables to store the count of 1 ' s ▁ and ▁ 0' s ; Length of the string ; For loop to count the occurrences of 1 ' s ▁ and ▁ 0' s in the string ; To check if the count of 1 ' s ▁ is ▁ ▁ greater ▁ than ▁ the ▁ count ▁ of ▁ 0' s or not . If x is greater , then those many 1 's  are printed. ; Length of the final remaining string after removing all the occurrences ; Printing the final string ; Driver Code
def finalString ( st ) : NEW_LINE INDENT x , y = 0 , 0 NEW_LINE n = len ( st ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( st [ i ] == '1' ) : NEW_LINE INDENT x += 1 NEW_LINE DEDENT else : NEW_LINE INDENT y += 1 NEW_LINE DEDENT DEDENT if ( x > y ) : NEW_LINE INDENT left = 1 NEW_LINE DEDENT else : NEW_LINE INDENT left = 0 NEW_LINE DEDENT length = n - 2 * min ( x , y ) ; NEW_LINE for i in range ( length ) : NEW_LINE INDENT print ( left , end = " " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT st = "010110100100000" NEW_LINE finalString ( st ) NEW_LINE DEDENT