Minimum number of characters to be removed to make a binary string alternate | Returns count of minimum characters to be removed to make s alternate . ; if two alternating characters of string are same ; then need to delete a character ; Driver code
< ? php function countToMake0lternate ( $ s ) { $ result = 0 ; for ( $ i = 0 ; $ i < ( strlen ( $ s ) - 1 ) ; $ i ++ ) if ( $ s [ $ i ] == $ s [ $ i + 1 ] ) $ result ++ ; return $ result ; } echo countToMake0lternate ( " 000111 " ) , " " ; echo countToMake0lternate ( " 11111 " ) , " " ; echo countToMake0lternate ( " 01010101 " ) ; ? >