Find the Intersection of Two Arrays
Easyjavapythonccppjavascript
Given two arrays, find the values that are present in both arrays. Each value must appear only once in the result.
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 common values in increasing order, separated by single spaces. If there are no common values, print an empty line.
Example 1
Input
4 1 2 2 4 4 2 2 3 4
Output
2 4
Explanation: 2 and 4 are present in both arrays.
- 1 <= N, M <= 100000
- -1000000000 <= A[i], B[i] <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Find the Largest ElementEasy · java, python, c, cpp, javascriptSolve Problem
- Find the Smallest ElementEasy · java, python, c, cpp, javascriptSolve Problem
- Find the Second Largest ElementEasy · java, python, c, cpp, javascriptSolve Problem