-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray Intersection.cpp
More file actions
53 lines (53 loc) · 1016 Bytes
/
Array Intersection.cpp
File metadata and controls
53 lines (53 loc) · 1016 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
51
52
53
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
vector<int> Max_Feq(int a[],int b[],int size1,int size2)
{
vector<int>output1;
unordered_map<int,int> m;
for(int i=0;i<size2;i++)
{
if(m.count(b[i])>0)
{
m.at(b[i])++;
continue;
}
m[b[i]]=1;
}
for(int i=0;i<size1;i++)
{
if(m.count(a[i])>0)
{
if(m.at(a[i])>0)
{
m.at(a[i])--;
output1.push_back(a[i]);
}
}
}
return output1;
}
int main()
{
int testCase,size1,size2;
//cin>>testCase;
cin>>size1;
int arr1[size1];
for(int i=0;i<size1;i++)
{
cin>>arr1[i];
}
cin>>size2;
int arr2[size2];
for(int i=0;i<size2;i++)
{
cin>>arr2[i];
}
vector<int> temp=Max_Feq(arr1,arr2,size1,size2);
sort(temp.begin(), temp.end());
for(int i=0;i<temp.size();i++)
{
cout<<temp[i]<<" ";
}
return 0;
}