#include
using namespace std;
int main() {
int n,B_count,A_count,length;
cin>>n;
char s[1000000];
cin>>s;
int maxim=1;
for(int i=0;i<s[i]!='\0';i++)
{
A_count++;
B_count++;
for(int j=i;j<s[j]!='\0';j++)
{
A_count=0;
B_count=0;
for(int k=i;k<=j;k++)
{
length=j-i+1;
if(s[k]=='a')
{
A_count++;
}
else
{
B_count++;
}
//now for making each substring eqaul we have to swap the characters.
int flip_a=length-B_count;
int flip_b=length-A_count;
if(flip_a<=n && length>=maxim)
{
maxim=length;
}
else if( flip_b<=n && length>=maxim)
{
maxim=length;
}
}
}
}
cout<<maxim;
return 0;
}
I’d solved this question, sample output is same but test cases are not passing , so can you please check what’s happening?