problem no 43:(array problem):Remove duplicate elements from sorted Array .
QUESTION:
Given a sorted array A of size N, delete all the duplicates elements from A.
Example 1:
Input:
N = 5
Array = {2, 2, 2, 2, 2}
Output: 2
Explanation: After removing all the duplicates
only one instance of 2 will remain.
Example 2:
Input:
N = 3
Array = {1, 2, 2}
Output: 1 2
ANSWER:
int remove_duplicate(int a[],int n){
set<int> s1;
for(int i=0;i<n;i++)
{
s1.insert(a[i]);
}
set<int, greater<int> >::iterator itr;
for (itr = s1.begin(); itr != s1.end(); itr++)
{
cout << *itr<<" ";
}
return 0;
}
Comments
Post a Comment