forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing_number.cpp
More file actions
50 lines (37 loc) · 689 Bytes
/
missing_number.cpp
File metadata and controls
50 lines (37 loc) · 689 Bytes
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
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
int hash1[N];
int hash2[N];
int main(){
int n,m;
cin>>n;
int a[n],b[n];
vector<int> res;
//input array and hashing
for(int i=0;i<n;i++)
{cin>>a[i];
hash1[a[i]]++;
}
cin>>m;
for(int i=0;i<m;i++)
{
cin>>b[i];
hash2[b[i]]++;
}
//checking
for(int i=0;i<m;i++){
if(abs(hash1[b[i]]- hash2[b[i]])!=0){
res.push_back(b[i]);
}
if(hash2[b[i]]!=0 && hash1[b[i]]==0){
res.push_back(b[i]);
}
}
sort(res.begin(),res.end());
res.erase( unique( res.begin(), res.end() ), res.end() );
for(int i=0;i<res.size();i++)
cout<<res[i]<<" ";
}