I got this problem from an interview with Microsoft.
Given an array of random integers, write an algorithm in C that removes duplicated numbers an
How about:
void rmdup(int *array, int length) { int *current , *end = array + length - 1; for ( current = array + 1; array < end; array++, current = array + 1 ) { while ( current <= end ) { if ( *current == *array ) { *current = *end--; } else { current++; } } } }
Should be O(n^2) or less.