Minimum removal of consecutive similar characters required to empty a Binary String | C ++ program for the above approach ; Function to find minimum steps to make the string empty ; Stores the modified string ; Size of string ; Removing substring of same character from modified string ; Print the minimum steps required ; Driver Code ; Given string S ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSteps ( string S ) { string new_str ; int N = S . length ( ) ; int i = 0 ; while ( i < N ) { new_str += S [ i ] ; int j = i ; while ( i < N && S [ i ] == S [ j ] ) ++ i ; } cout << ceil ( ( new_str . size ( ) + 1 ) / 2.0 ) ; } int main ( ) { string S = "0010100" ; minSteps ( S ) ; return 0 ; }