2 test cases fail

https://ide.codingblocks.com/s/230912 Please tell what’s the problem in this code.

@payal_05 the code you have written, assumes that all the a occur together then b occur together, it is possible that the selected sequence of ab do not cover all alphabet with larger count,

k=2
abaaabbaabaaa
Answer = 7;
Your answer 6.
To solve the problem, maintain the frequency of a and b in a range and till the min of frequency is less than of equal to k, do nothing and keep taking maximum of answer with sum of frequency, when min frequency is greater than k, move the start position and keep updating frequency till min frequency is not equal to k.
If this resolves your doubt mark it as resolve.d