Find the Union of Two Arrays
Easyjavapythonccppjavascript
Given two arrays, create the set of every distinct value that appears in either array.
Input Format
The first line contains an integer N. The second line contains N space-separated integers (array A). The third line contains an integer M. The fourth line contains M space-separated integers (array B).
Output Format
Print the distinct values from either array in increasing order, separated by single spaces.
Example 1
Input
4 1 2 2 4 4 2 3 4 5
Output
1 2 3 4 5
Explanation: All distinct values from both arrays, listed once.
- 1 <= N, M <= 100000
- -1000000000 <= A[i], B[i] <= 1000000000