Doubt in sanket and string

while swapping how to choose between “a” and “b” as to which one should I swap in order to get max substring?

do I need to make two different cases :

  1. check max substring in ‘a’ by swapping ‘b’
  2. check max substring in ‘b’ by swapping ‘a’

and print the maximum one ?

yes, we will perform 2 iteration first trying to construct maximum subarray of a then maximum subarray of b and the answer would be bigger subarray amongst them.

okay let me try this approach

Hey I tried it many times, I read all these editorials, still I think i’m missing something. I am literally stuck in this problem.
it would be great if you could please share your code with detailed explanation.

:sob::sob::innocent:

one of my several idiotic approach :

the logic for solving this problem is a simple one, we begin with 2 pointers left and right, we freeze left and increase right till it is possible to make string from left to right of one character once number of different character exceeds k, we move left pointer till it becomes less than k and then we freeze left pointer and move right and this process continues till right reaches n. We do this because this way we can find the maximum solution for each left.

In this approach i solved for both a and b at the same time but you can also do it twice once for a and then for b it will work just fine.

hey please put comments in your code elaborating what a particular statement achieves.

thank you.:pray:

1 Like

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.