Not able to solve it ,sanket and string

#include
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int k;
cin>>k;
cin.get();
string s;
getline(cin,s);
char x;
map <char,long long int> mp;
for(int i=0;i<s.size();i++)
{
mp[s[i]]++;
}
auto it=max_element(mp.begin(),mp.end());
x=it->first;
long long int y=it->second;
for(long long int i=0;i<s.size();i++)
{
if(s[i]!=x && k!=0)
{
y++;
k–;
}
}
cout<<y;
return 0;
}

Hi @firozbhaikardar21 you can refer to this code https://ide.codingblocks.com/s/106500

We are taking minimum count to find the character(either a or b) which has occurred less no of times till that particular iteration.
Because we would change the occurrence of only that character which are in minority, to determine the , maximum value.

We are comparing the minimum value with k because we can make k changes at max.
If, the minimum count is greater than k , then it means that we cannot swap all the occurrence of the character that has lesser count.
Thus, we increment l.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.