Sanket and strings

i am not able to understand the approaches two pointer approaches so can you please dry run on more complex inputs so the approach is clear. I have read the editorial but didn’t help me much.
Instead of giving the steps plz explain how the approach works ?

Here we are trying to find max substring length of a which can be made and max substring of length b which can be made,then will take max of two values.


Read this for more better explanation.
Here we are applying this two times:
1)to find max length a which is possible
2)to find max length b which is possible

@Mohitpandey29
i got some understand let me know if m wrong or right…
we have a string our task is find the maxlenght of that substring in which all the character are same.
so using two approach approach what we did.

  1. we initizate left , right to 0.
  2. we have the left pointer as fixed and iterate over the string using the right pointer
  3. so let assume we in first case we replace the b character k times means k swaps
  4. so, at each postition we check is the char is ‘a’ means its lenght is one so max = right - left +1
  5. at if any pos of right we found b we are going to stop and decrement the count by k which is nothing but the occurence of the same element and untill the left pointer reaches to right it means we have found one substring and assign to max varible and soon.

Yes kind of correct.
What we are doing is trying to find the maximum substring of all a first then all b.
For all a, we are keeping a left and right pointer and then keeping count of B occurred till now,
Once it becomes k we are updating the max length to be current - left +1 and updating left to be first occurrence of B in the current string and decreasing K by 1 as we have removed one b

If count never becomes k then answer is n-left.
Same for B as well and return max of two.