I am having a doubt in the question named alternating binary string that came in starters 130
#include<bits/stdc++.h>
using namespace std;
define ll long long
int main()
{
int t;
cin >> t;
while (t–) {
int n;
cin >> n;
string s;
cin >> s;
ll count = 0;
ll consec = 0;
for (int i = 0; i < n; i++) {
if (s[i] == ‘0’) {
consec++;
} else {
count += ((consec) / 2);
consec = 0;
}
}
ll consec1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == ‘1’) {
consec1++;
} else {
count += ((consec1) / 2);
consec1 = 0;
}
}
count += ((consec1) / 2);
count += ((consec) / 2);
cout << count << endl;
}
return 0;
}
My code is this i couldnt think of where my code fails. here’s the link of the question Alternating Binary String Practice Coding Problem - CodeChef.