Problem - 1028923 - Codeforces[
^]
Quote:
Please help???
It is amazing to see how your small piece of code is complicated for such a simple problem.
Using recursion is overkill and storing 'a's every where in string is unnecessary.
All you need is keep track of last 'a' and last 'b'.
int letters(string &s){
int counter= 0;
int LastA= -2;
int LastB= -1;
for (int i= 0; i<s.length(); i++) {
if (s[i]== 'a') {
}
else if (s[i]== 'b') {
}
}
return counter;
}
This code is only general structure and not intended to give a full solution.