-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRemove Duplicate Elements.cpp
More file actions
77 lines (63 loc) · 1.82 KB
/
Remove Duplicate Elements.cpp
File metadata and controls
77 lines (63 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Geeks For Geeks */
/* Title - Remove duplicate elements from sorted Array */
/* Created By - Akash Modak */
/* Date - 04/09/2020 */
// Given a sorted array A of size N. The function remove_duplicate takes two arguments . The first argument is the sorted array A[ ] and the second argument is 'N' the size of the array and returns the size of the new converted array A[ ] with no duplicate element.
// Input Format:
// The first line of input contains T denoting the no of test cases . Then T test cases follow . The first line of each test case contains an Integer N and the next line contains N space separated values of the array A[ ] .
// Output Format:
// For each test case output will be the transformed array with no duplicates.
// Your Task:
// Your task to complete the function remove_duplicate which removes the duplicate elements from the array .
// Constraints:
// 1 <= T <= 100
// 1 <= N <= 104
// 1 <= A[ ] <= 106
// Example:
// Input (To be used only for expected output) :
// 2
// 5
// 2 2 2 2 2
// 3
// 1 2 2
// Output
// 2
// 1 2
// { Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
/*You are required to complete this function */
int remove_duplicate(int [],int );
int main()
{
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
int a[N];
for(int i=0;i<N;i++)
{
cin>>a[i];
}
int n = remove_duplicate(a,sizeof(a)/sizeof(a[0]));
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}
// } Driver Code Ends
/*You are required to complete this function */
int remove_duplicate(int A[],int N)
{
//Your code here
int i=0,j=1;
for(;j<N;j++){
if(A[i]!=A[j]){
i++;
A[i]=A[j];
}
}
return i+1;
}