Tuesday, March 12, 2013

Program to remove duplicates in sorted array

This has been asked multiple times at multiple places. In fact, it is one of the Puzzle I had seen at Amazon Interview 2010

Write a program / algorithm to remove duplicates from a sorted array.


PS: You can devise other means. In case, you find your answer to be more efficient, let the community know about that. After posting here , you can personally email me at Toughjamy@Yahoo.com for review.

int remove_duplicates_in_Sorted_Array(int * p, int size)
int c, i = 1;
for (c=1; c < size; c++)
if (p[c] != p[i-1])
p[i] = p[c];
c++; i++;
else {c++;}
return i;}

No comments:

Post a Comment