Dsa
Hashing
Medium
Common Elements in Two Arrays
Given two arrays of integers, find the common elements that are present in both arrays. The output should be unique common elements, sorted in ascending order.
Input Format:
The first line contains an integer N, the size of the first array. The second line contains N space-separated integers. The third line contains an integer M, the size of the second array. The fourth line contains M space-separated integers.
Output Format:
Print the common elements sorted in ascending order, each on a new line.
Example:
Input:
5
1 2 3 4 5
3
4 5 6
Output:
4
5
Key concepts
hashingarraysintersection
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now