78. Intersection of Two Arrays
EasySet
Print the distinct values present in both arrays in increasing order, or -1 if none.
Input format
Line 1: n Line 2: n integers Line 3: m Line 4: m integers
Output format
The common values, or -1.
Example 1
Input
4 1 2 2 1 2 2 2
Output
2
Example 2
Input
3 4 9 5 5 9 4 9 8 4
Output
4 9
Constraints
1 ≤ n, m ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…