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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started