You are given two integer arrays. Find every value that appears in both arrays. List each such value once, sorted in ascending order.
If no value is common to both arrays, print an empty line.
Line 1: an integer n, the size of the first array.
Line 2: n space-separated integers, the first array.
Line 3: an integer m, the size of the second array.
Line 4: m space-separated integers, the second array.
One line: the common values, each printed once, in ascending order, space-separated. If there are none, print an empty line.
Example 1
Input
4 1 2 2 3 3 2 3 4
Expected
2 3
Explanation
The first array holds {1,2,3}, the second holds {2,3,4}. Both contain 2 and 3, so the answer is '2 3'.
Example 2
Input
3 5 6 7 2 8 9
Expected
(empty)Explanation
The arrays share no value, so the output is an empty line.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →