Minimum number of elements to be removed so that pairwise consecutive elements are same | C ++ implementation of the above approach ; Function to count the minimum number of elements to remove from a number so that pairwise two consecutive digits are same . ; initialize counting variable ; check if two consecutive digits are same ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countConsecutive ( string s ) { int count = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) i ++ ; else count ++ ; } return count ; } int main ( ) { string str = "44522255" ; cout << countConsecutive ( str ) ; return 0 ; }