Minimum number of deletions so that no two consecutive are same | CPP code to count minimum deletions required so that there are no consecutive characters left ; Function for counting deletions ; If two consecutive characters are the same , delete one of them . ; Driver code ; Function call to print answer
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDeletions ( string str ) { int ans = 0 ; for ( int i = 0 ; i < str . length ( ) - 1 ; i ++ ) if ( str [ i ] == str [ i + 1 ] ) ans ++ ; return ans ; } int main ( ) { string str = " AAABBB " ; cout << countDeletions ( str ) ; return 0 ; }