Sanket and strings

I m not getting the question plz explain and how I proceed

Hi @parasjain011999
Basically in this ques you are given string of ‘a’ and ‘b’ and are given an integer k. You have to find max length substring of same character which can be formed using k times changing of any character. Suppose you are given string as baabaaabb and k=2. Then you can replace 2 character of this string so as to form a max length substring. So maximum length sub string can be formed when we replace ‘b’ at index 0 and 3 to ‘a’ then we have a substring aaaaaaa of length 7. This is how you have to find the maximum length substring.

Basic approach for this ques is :

  1. We check for maximum length of sub-string that can be formed by a and b.
  2. For doing this we traverse whole string and whenever we find a different character, we increase the count.
  3. If count becomes greater than k (at right index), we again start from 0th index and if we found different character we will decrease the count.
  4. When count will be equal to k (at left index) then at that point the length will be rightIndex-leftIndex+1.
  5. We repeat this process until we reach at the end of string and at that point we will return the maximum length.
  6. We do this for all characters and finally return the maximum length.