kindly discuss its approach
Not able to think the algorithm
hi @namangarg31, You can solve this problem in O(n) time using the two pointer approach.
Make two variabes , say i and j .
i defines the beginning of a window and j defines its end.
Start i from 0 and j from k.
Let’s talk about the singular case when we are considering the max window for only 'a’s and consider only the swapping of b-> a. If we are able to get the answer for max window of consecutive 'a’s , we can simply implement the same algo for the max ‘b’ window as well.
So we started i from 0 and j from k.
Move j ahead freely as long as there are ‘a’ characters at s[ j ] position.
Maintain a count variable which counts the number of swaps made or the number of 'b’s in our A window.
If you encounter a ‘b’ char at s[ j ] position , increment the count variable. Count should never exceed k .
Take the size of the window at every point using length = j - i + 1;
Compute the max size window this way and do the same for ‘b’ as well.
Output the maximum size window of ‘a’ and ‘b’.
Try to dry run this approach on the given example
In case of any doubt feel free to ask 
If you got the answer then mark your doubt as resolved
please share its code, i don’t understand why we are starting j from k and what about the elements between i and k
the algo which i suggested is called as sliding window , here i and j makes a window of valid substring.
here’s the code with proper comments
correction:
instead of starting j from k .what we do is from j=0 we will increment j until we have k swaps , such that we obtain maximum substring starting from 0 with k swaps i.e(initialize the window)
this is little tricky to understand at first make sure to dry run this code.