I was doing practice on search algorithms for arrays.
I had come across with problem of finding missing and duplicate element by using XOR approach for a given array of elements containing integer from 1 to n. Find the missing and duplicate elements in an array in linear time and constant space I am very well able to understand that how we can get the separate values of X and Y ( one is repeating and another is duplicate )
However I am unable to understand how are we able to decide that which one is repeating and which one duplicate.
( as per given solutions I could see xor result of XOR over list which has set-bit gives missing element and other list gives duplicate ). However I am unable to understand the logic to reach on this decision.
Please help me to understand the logic behind this decision.