One test case is failing

Hi @ksalokya
refer this https://ide.codingblocks.com/s/624981

yeah i have checked it, i applied the same approach just wanted to know in line number 18, 36, 51 why you have taken s.size-1.

fir line number 36 and 51 i guess because we are increasing right by 1 that’s why, but why in line 18?

  • 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’.

well explained, just a last doubt, check this link https://ide.codingblocks.com/s/625329

line 17, in for loop why we have to consider size-1, can’t it be size?

2
abaa
dry run for this input with size-1 and size… u will get to know the diff

that was an awesome explanation. thanks a lot, you can close this thread.

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.