SanketAndStrings

https://ide.codingblocks.com/
please tell the error int this code

Hey Pritika, save your code on online ide and then share that link, the link you have mentioned doesn’t have your code.

https://ide.codingblocks.com/s/52048

Hey Pritika, your approach is wrong, this problem is pretty simple, here I am sharing my code snippet you can refer this

 int k;
  cin>>k;
    string str;
    cin>>str;
    int left=0, ans=0;
    int count[2] = {0};
    for (int i=0;i < str.length();i++) {
        char c =str[i];
        count[c-'a']++;
        if(min(count[0], count[1]) > k) {
            count[str[left]-'a']--;
            left++;
        } else {
            ans++;
        }
    }
    cout<<ans;