Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr[n];
map<int, bool> inp;
int x, k = 0;
for(int i = 0; i < 2*n; i++){
cin>>x;
if(!inp[x]){
arr[k] = x;
inp[x] = true;
k++;
}
}
for(int i = 0; i < n; i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
5
2
1 1 2 2
4
1 3 1 4 3 4 2 2
5
1 2 1 2 3 4 3 5 4 5
3
1 2 3 1 2 3
4
2 3 2 4 1 3 4 1
2
1 1 2 2
4
1 3 1 4 3 4 2 2
5
1 2 1 2 3 4 3 5 4 5
3
1 2 3 1 2 3
4
2 3 2 4 1 3 4 1
Output
1 2
1 3 4 2
1 2 3 4 5
1 2 3
2 3 4 1
1 3 4 2
1 2 3 4 5
1 2 3
2 3 4 1
Demonstration
Codeforcess solution 1385-B B. Restore the Permutation by Merger ,C++, Java, Js and Python,1385-B,Codeforcess solution