Getting WA on 1 test case in Hail EXOR

problem link : https://www.codechef.com/problems/HXOR
my solution : https://www.codechef.com/viewsolution/40454025

In line 62, you are selecting j on the basis of p > arr[j], which means you are assuming that :
p ^ arr[j] < arr[j] for all values of arr[j] > p, which is not true when arr[j] is power of 2.

e.g. for 5 8 7,
For i=1, p=4 and you will select j=2. But 4^8 is actually > 8. Our goal is to minimize, so choose j only if (arr[j] ^ p) < arr[j]

1 Like

It’s hard to debug a code directly. What I would suggest you is pick some correct solution from the correct ones submitted and yours, then call them as 2 methods by generating random inputs in an infinite loop. Whenever the return values of both the methods are unequal, print the inputs and break. Then you can figure out the issue.

1 Like

Thanks Got it : )

Sure will follow this from now onwards.