How to find duplicates in an array. In the case of the inverse problem, when you need to find a unique element from all, it is clear that you are just xor all the elements, and as a result we get a unique element. For instance,
int a[] = {2, 2, 3, 3, 4, 5, 5, 16, 16}; int res = a[0]; for(int i = 0; i < 9; ++i) res ^= a[i];
for example for an array
int a[] = {2, 4, 7, 8, 4, 5};
Here the duplicate is 4, but it is not clear how to find the duplicate element of the array.
user1886376
source share