Sanket and strings

what is wrong in this code .Two test cases are failing

Hello @Jitu748

May be you forgot to put in the link to your code.

Hello @Jitu748

In this question you are given an integer k and a string of ‘a’ and ‘b’. What you need to do is that you have to replace either ‘a’ by ‘b’ or ‘b’ by ‘a’ at most k time so that you get a string of maximum length of either continuous ‘a’ or continuous ‘b’.
For example
k = 2
string = “aabababaabb”
If we replace b at index 2 and index 4, we get string of a of length 6 and 6 is the perfectness of the above string.

Here is the code

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.