Question: // REQUIRES: there are at least n elements in arr; // n >= 0; // the elements of arr are sorted in ascending order; //
// REQUIRES: there are at least n elements in arr;
// n >= 0;
// the elements of arr are sorted in ascending order;
// there may be duplicates
// MODIFIES: the elements in arr
// EFFECTS: Removes duplicate elements from arr. Returns the number
// of unique elements, and modifies arr to contain those
// unique elements in sorted order at the beginning. The
// values that come after the unique elements are
// unspecified (they are allowed to be anything).
// EXAMPLE: If arr contains, [1,2,2,3,3], it would be modified to
// contain [1,2,3,?,?] (where ? means the value can be
// anything), and the return value would be 3
// NOTE: You must use traversal by pointer.
// Your solution must be in-place and run in linear time.
int removeDuplicates(int arr[], int n) {
// TASK 4 (OPTIONAL) - REPLACE WITH YOUR CODE
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
