What is the difference between these two?

While I was solving CNOTE, I set bool = true and implemented the solution. The solution worked fine in my IDE but on Codechef IDE it threw WA. here’s the link to that solution: https://www.codechef.com/viewsolution/15904044

But when I changed bool to false and then implemented the same code, it got AC. Here’s the link: https://www.codechef.com/viewsolution/15904061.
Please help me in finding my mistake with the original solution.

In the first code you were constantly changing the value of the bool in the loop. This resulted the flag to have the value which is only the result of the last iteration. In your second code, you changed it and then set flag = true and then break, this took the result of the first occurrence of the index which satisfied the equation. This is the reason you got WA the first time and AC the second time. Changing bool to false isn’t the only change you made :P.

1 Like

yo lol :D…

1 Like