Deletions of "01" or "10" in binary string to make it free from "01" or "10" | C ++ implementation of the approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int substrDeletion ( string str , int len ) { int count0 = 0 , count1 = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) count0 ++ ; else count1 ++ ; } return min ( count0 , count1 ) ; } int main ( ) { string str = "010" ; int len = str . length ( ) ; cout << substrDeletion ( str , len ) ; return 0 ; }