WA in CHARGES problem after multiple attempts

PROBLEM LINK :- CodeChef: Practical coding for everyone
MY SUBMISSION:- CodeChef: Practical coding for everyone

I tried multiple times using sample test cases. Everything looks fine but it’s still giving WA after submitting . Can anyone please point out the test case, due to which it’s throwing a WA?

Thank you :relaxed:

n=1 will give wrong ans

1 Like
                if(s[Qi]==s[Qi+1])
	            dist--;
	            else if(s[Qi]!=s[Qi+1])
	            dist++;
	            if(s[Qi]==s[Qi-1])
	            dist--;
	            else if(s[Qi]!=s[Qi-1])
	            dist++;

This part of your code is contributing in the wrong answer.

            if(s[Qi]==s[Qi-1])
	            dist--;
	            else if(s[Qi]!=s[Qi-1])
	            dist++;

Check again, the above part of code is bypassed since one of the former two conditions must be true.

1 Like

Even if I do this i.e using if instead of else if its giving WA…
You can see that code here CodeChef: Practical coding for everyone

Screenshot 2021-06-01 at 12.17.08 AM

yeah!! I think thats the issue… Thanks :smiling_face_with_three_hearts: