Skip to content

Commit

Permalink
Status:solved
Browse files Browse the repository at this point in the history
  • Loading branch information
Sundar2k4 committed Aug 8, 2024
1 parent 99727d3 commit f29f7eb
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions union.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <bits/stdc++.h>
using namespace std;

// } Driver Code Ends
class Solution
{
public:
// arr1,arr2 : the arrays
// n, m: size of arrays
// Function to return a list containing the union of the two arrays.
vector<int> findUnion(int arr1[], int arr2[], int n, int m)
{
// Your code here
// return vector with correct order of elements
set<int> ar;
for (int i = 0; i < n; i++)
{
ar.insert(arr1[i]);
}
for (int j = 0; j < m; j++)
{
ar.insert(arr2[j]);
}

vector<int> arr(ar.size());
int l = 0;
for (int k : ar)
{
arr[l++] = k;
}

return arr;
}
};

//{ Driver Code Starts.

int main()
{

int T;
cin >> T;

while (T--)
{

int N, M;
cin >> N >> M;

int arr1[N];
int arr2[M];

for (int i = 0; i < N; i++)
{
cin >> arr1[i];
}

for (int i = 0; i < M; i++)
{
cin >> arr2[i];
}
Solution ob;
vector<int> ans = ob.findUnion(arr1, arr2, N, M);
for (int i : ans)
cout << i << ' ';
cout << endl;
}

return 0;
}

0 comments on commit f29f7eb

Please sign in to comment.