the code snippet is
#include<bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
string str;
int k; cin >> k;
cin >> str;
int maxa = 0, maxb = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ‘a’)
maxa++;
else
maxb++;
}
cout << max(min(maxa, maxb) + min(max(maxa, maxb), k) , max(maxa, maxb) + min(min(maxa, maxb), k));
}
Idk why my 1st and 2nd test case is wrong
@ANIKET_DALAL
Your code will fail on test cases like : 2
bbbaaabbbab
Your program gives output 9 whereas correct answer is 6.