I am able to pass 2 out of 3 test cases from this solution https://ide.codingblocks.com/s/321635
But dont know why 3rd one is not getting passed.As i have taken care of K=0 as well.
Test cases not getting passed completely
@TusHar-AroRa-2294450460870717
I am having a look at your code.
In the meantime, just go through my code.
I hope it helps you.
@TusHar-AroRa-2294450460870717
There was a small error in your code. You were checking whether kcopy was zero without checking that the element str[j] was favorable to you or not. This is reason why you were not able to attain longest length. Also after you have run the loop when kcopy == 0 is encountered, set currCount to (j - i) and not
(j - i + 1) because the length of segment with all the characters equal to equal to (j - i) and not (j - i + 1).
Dry run it and you will be able to understand it.
This is your updated code.
If my explanation was able to answer your query, please mark the doubt as solved.
Ok got it but can u ples explain why currcount=(j-i) instead of (j-i+1).
for eg if i is 0 and j is 2 then length will be 3 not 2
@TusHar-AroRa-2294450460870717
If j is 2, then j hasnt been verified yet. This is the reason the length is (j - i).