#include int removeDuplicates(int*, int); int removeDuplicates(int* nums, int numsSize) { if (numsSize == 0) { return 0; } int shift = 0; int last = nums[0] + 1; // This way the first item will never be a duplicate for (int i = 0; i < numsSize; i++) { int value = nums[i]; nums[i - shift] = value; if (value == last) { shift++; } last = value; } return numsSize - shift; } int main() { printf("Expetected: Length 5, [0, 1, 2, 3, 4]\n"); int arr[10] = {0,0,1,1,1,2,2,3,3,4}; int newLength = removeDuplicates(&arr[0], 10); // &arr[0] is a hack to stop warning about static sized pointer being passed printf("Got: Length: %d,", newLength); for (int i = 0; i < newLength; i++) { printf(" %d ", arr[i]); } printf("\n"); return 0; }