Sanket and strings problem

sir i got this code from the editorial and i have some doubts in this problem. when i submit this code then this does not passes some test cases.
in line no 27 i have written
for(j; j<=s.length()-1 && c<=k; ++j)
but when i submit this then it does not pass all test cases but if i remove inequality from this line that is instead of writing <= when we write only < then it passes all test cases.
also in line no 36 i have the same problem. why we have to write only <. <= should be there. line 36 -
while(s[j+1]==ch && j<=s.length()-1)
i have the same problem in line no 41 -
if(j<=s.length()-1 && s[i-1]!=ch)
here also why are we using only <. why there is no <= ?

can somebody please explain me the complete while loop?

while(i<j)
{
while(s[j+1]==ch && j<=s.length()-1)
++j;
int currentLength = j-i+1;
ans = max(currentLength, ans);
++i;
if(j<=s.length()-1 && s[i-1]!=ch)
++j;
}
i am not able to understand after the increementation of i ?

here is my code -

@pushkar24sharma see this code, it’s modified and commented for better understanding

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.