Deletions of "01" or "10" in binary string to make it free from "01" or "10" | Function to return the count of deletions of sub - strings "01" or "10" ; To store the count of 0 s and 1 s ; Driver code
function substrDeletion ( str , len ) { let count0 = 0 , count1 = 0 ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) count0 ++ ; else count1 ++ ; } return Math . min ( count0 , count1 ) ; } let str = " " ; let len = str . length ; document . write ( substrDeletion ( str , len ) ) ;