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 ; Variable left will store whether 0 ' s ▁ or ▁ 1' s is left in the final String ; 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 prleted. ; Length of the final remaining String after removing all the occurrences ; Printing the final String ; Driver Code
function finalString ( str ) { let x = 0 , y = 0 ; let left ; let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) x ++ ; else y ++ ; } if ( x > y ) left = 1 ; else left = 0 ; let length = n - 2 * Math . min ( x , y ) ; for ( let i = 0 ; i < length ; i ++ ) { document . write ( left ) ; } } let str = " " ; finalString ( str ) ;