#include
#include
using namespace std;
int length(string s, int k)
{
int a_len = 0, b_len = 0;
int len = s.length();
for(int i = 0; i < len; i++)
{
if(s[i] == ‘a’)
a_len++;
else
b_len++;
}
if(a_len == b_len)
return 2 * a_len;
while(k–)
{
if(a_len == b_len)
return 2 * a_len;
else if(a_len < b_len)
{
a_len++;
b_len–;
}
else
{
a_len–;
b_len++;
}
}
if(a_len < b_len)
return 2* a_len;
return 2* b_len;
}
int main()
{
int n;
cin>>n;
string s;
cin>>s;
cout<<length(s, n);
return 0;
}
I am able to clear only one test case, please suggest some test cases and where I am doing wrong