Https://ide.codingblocks.com/s/482005

I am getting error due to replace function used in my code but if i dont use it then how will i swap a & b and my code is also not working.

hello @architsuryavanshi

what u r trying here? whats ur logic?

i am just trying to replace all b with a in this string by checking if it is a or b can you tell me some another approach of this

…

that will no work.
here u need to find the maximum length of a substring (consecutive subsequence) consisting of equal letters. and u are allowed to change no more than k characters of the original string.

for example->
4 2
abba

answer is 4 becuase can obtain both strings “aaaa”(by change 2 b’s into a) and “bbbb”(changing a’ to b)

8 1
aabaabaa
answer is 5 becuase we can obtain string “aaaaabaa” or string “aabaaaaa”. (both have 5 length substring with all smae character)

This problem can be solved with help of two pointers. Let the first pointer is l and the second pointer is r . Then for every position l we will move right end r until on the substring Sl Sl + 1… Sr it is possible to make no more than k swaps to make this substring beautiful. Then we need to update the answer with length of this substring and move l to the right.

still ur solution is showing error i tried to figure it out but i wasn’t able to

@architsuryavanshi

check now

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.