Sanket and strings challenge

#include<bits/stdc++.h>
using namespace std;

int main(){
int k;
cin>>k;
string str;
cin>>str;
int ans=0;
int count[]={0,0};
int l=0;
for(int r=0;r<str.length();r++){
char a = str[r];
count[a - ‘a’]++;
if(min(count[0], count[1]) > k){
count[str[l] - ‘a’]–;
l++;
}
else
ans++;
}
cout<<ans;
return 0;
}

I read this code in doubts regarding this challenge.I am not able to understand the logic behind it.Please explain it.

This code is showing compilation error.
In this question as there are only two characters in the string,so if we have to consider max length of string a possible with atmost k changes and similarly for b.
You can make two seperate functions one which checks max length possible for string a while other for string b.