Removing duplicates in an array in one pass

int insertAt=0,index;
for(index=insertAt+1;index
if(a[insertAt] == a[index])
index+=1;
else
a[insertAt++] = a[index];
}
insertAt–;

Identification of duplicant element in an array
Identify the element that is not repeating in an array of 2n+1 elements, in O(n) time
X-or all the elements, same elements cancel each other.

Leave a Reply

Your email address will not be published. Required fields are marked *