My code is failing for two testcases?

#include
#include
using namespace std;

int find(string s,int k,char ch)
{
int n = s.length();
int count = 0;
int i = 0,j;
int best = 1;

while(i<n)
{
    j = i;
    while(j<n)
    {
        if(count==k)
        {
            break;
        }
        else if(s[j]!=ch)
        {
            count++;
        }
        j++;
    }
    best = max(best,j-i);
    i++;
    count = 0;
}
return best;

}

int GetMaxSame(string s,int k)
{
int maxLen = 1;
maxLen = max(maxLen,find(s,k,‘a’));
maxLen = max(maxLen,find(s,k,‘b’));
return maxLen;
}

int main()
{
int k;
cin>>k;

string s;
cin>>s;

cout<<GetMaxSame(s,k);
return 0;

}

@Deepanshu_garg hey I can suggest better implementation this problem have larger test set so this question require linear implementation.