-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day_048.cpp
56 lines (40 loc) · 806 Bytes
/
Day_048.cpp
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
/**
*Problem Statement: a Program to remove duplicate elements in an array.
*Author: Kunal Kathpal (https://github.com/kunal-2002)
*/
#include <bits/stdc++.h>
using namespace std;
int solve(int arr[], int n){
if(n==0 || n==1)
return n;
int temp[n];
int j=0;
for(int i=0;i<n-1;i++){
if(arr[i] != arr[i+1])
temp[j++] = arr[i];
}
temp[j++] = arr[n-1];
for(int i=0;i<j;i++){
arr[i] = temp[i];
}
return j;
}
int main(){
cout<<"Enter number of test cases:\t";
int T;
cin>>T;
while(T--){
int size ;
cout<<"Enter size of array:\n";
cin>>size;
int arr[size];
cout<<"Enter the elements:\n";
for(int i=0;i<size;i++)
cin>>arr[i];
size = solve(arr, size);
for(int i=0; i<size; i++)
cout<<arr[i]<<" ";
cout<<endl;
}
return 0;
}