HackerRank 'Alternating Characters' Solution

by Srikant Padala on June 25, 2016, 10:31 am


Explanation



Alternating Characters Problem Statement

Video

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int getNumDeletion(string &str) {
    int count = 0;
    for(int i=0 ; i < str.size()-1; i++) {
        if(str[i] == str[i+1]) count++;
    }
    return count;
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int t;
    cin >> t;
    string str;
    while(t--) {
        cin >> str;
        cout << getNumDeletion(str) << endl;
    }
    return 0;
}

Coming Soon.