Sanket and strings

how to approach give me some hint?
i have tried counting a and b and thern replacing
also i have tried s[i]!=s[i-1]
but these will fail when we have to change in between>

You need to maintain count of each character, and see which character has minimum count for each substring, if min count is less than k, then for that substring we can make all character equal to majority and the length of subarray will become candidate for answer, you need to length of subarray that is maximum.
Now you need to use the uniqueness of string that only 2 characters are present to calculate all possible subarrays in O(n). Try to do it, if you find difficulty I would help.

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.