#include<bits/stdc++.h>
using namespace std;
int removeDuplicates(int arr[], int n)
{
int i = 0;
for (int j = 1; j < n; j++) {
if (arr[i] != arr[j]) {
i++;
arr[i] = arr[j];
}
}
return i + 1;
}
int main() {
int arr[] = {1,1,2,2,2,3,3};
int n = sizeof(arr)/sizeof(arr[0]);
int k = removeDuplicates(arr, n);
cout << "The array after removing duplicate elements is " << endl;
for (int i = 0; i < k; i++) {
cout << arr[i] << " ";
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCByZW1vdmVEdXBsaWNhdGVzKGludCBhcnJbXSwgaW50IG4pCnsKICBpbnQgaSA9IDA7CiAgZm9yIChpbnQgaiA9IDE7IGogPCBuOyBqKyspIHsKICAgIGlmIChhcnJbaV0gIT0gYXJyW2pdKSB7CiAgICAgIGkrKzsKICAgICAgYXJyW2ldID0gYXJyW2pdOwogICAgfQogIH0KICByZXR1cm4gaSArIDE7Cn0KaW50IG1haW4oKSB7CiAgaW50IGFycltdID0gezEsMSwyLDIsMiwzLDN9OwogIGludCBuID0gc2l6ZW9mKGFycikvc2l6ZW9mKGFyclswXSk7CiAgaW50IGsgPSByZW1vdmVEdXBsaWNhdGVzKGFyciwgbik7CiAgY291dCA8PCAiVGhlIGFycmF5IGFmdGVyIHJlbW92aW5nIGR1cGxpY2F0ZSBlbGVtZW50cyBpcyAiIDw8IGVuZGw7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBrOyBpKyspIHsKICAgIGNvdXQgPDwgYXJyW2ldIDw8ICIgIjsKICB9Cn0=