Doubt within logic

In this function why all test cases pass when i do right<s.length()-1 and one test case fail if i do right<s.length().

for (right; right < s.length()-1; right++)
   {
       if (s[right]!=ch)
       {
           count++;
       }
       if (count==n)
       {
           break;
       }
   }

this is complete code https://ide.codingblocks.com/s/271209

@sagar_aggarwal because at last right will get incremented so assume s.length() as n so if loop till <s-1 so at last right will become s-1 while is the last index
other case loop til <n so right at end becomes n while is outside the string

got your point vatsal but in case c<k and suppose last of minimum k swap could be done at a[s.length()-1] then that value will be ignored?

are you there?? @vatsal38

@sagar_aggarwal if last index swap is being done it would have been done some where before only no need. also in later part of code right+1 is happening when right<s.length()-1