I have seen the solution for this problem in this thread -> How to find a duplicate element in an array of shuffled consecutive integers?
But the problem I am now having is little varied from it.
int arr[10] = {1,2,3,4,5,6,7,8,4,9};
int a= 0;
for(int i=0;i<10;i++) {
a= a^ arr[i] ^i;
}
cout<<a;
Consider the above mentioned code snippet. Things work fine as it is. But when I add a 0 to the above mentioned array like, int arr[11] = {0,1,2,3,4,5,6,7,8,4,9};
I am not getting the proper duplicate element. Can somebody correct me the mistake I am making here?