-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGFG_UnionTwoArrays.cpp
57 lines (41 loc) · 1 KB
/
GFG_UnionTwoArrays.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
57
/*
https://practice.geeksforgeeks.org/problems/union-of-two-arrays3538/1#
Union of two arrays
*/
// { Driver Code Starts
//Initial template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function template in C++
class Solution{
public:
//Function to return the count of number of elements in union of two arrays.
int doUnion(int a[], int n, int b[], int m) {
// int count=0;
set<int> s;
// int len = min(m,n);
for(int i=0; i<n; i++)
s.insert(a[i]);
for(int i=0; i<m; i++)
s.insert(b[i]);
return s.size();
}
};
// { Driver Code Starts.
int main() {
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
int a[n], b[m];
for(int i = 0;i<n;i++)
cin >> a[i];
for(int i = 0;i<m;i++)
cin >> b[i];
Solution ob;
cout << ob.doUnion(a, n, b, m) << endl;
}
return 0;
} // } Driver Code Ends