Sanket and striny

Please tell me the approach to solve the problem

Hey, you can use the two pointer approach for this problem as the string will consist of only a and b, you can use 2 pointers to count their occurrences. 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.

Hey, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.