Dsa
Arrays
Easy
Common Elements in Three Sorted Arrays
Given three sorted arrays, find the common elements among them. The output should contain each common element only once, even if it appears multiple times in the input arrays.
Input format:
- The first line contains an integer n1 (1 <= n1 <= 10^5), the length of the first array.
- The second line contains n1 space-separated integers, elements of the first array.
- The third line contains an integer n2 (1 <= n2 <= 10^5), the length of the second array.
- The fourth line contains n2 space-separated integers, elements of the second array.
- The fifth line contains an integer n3 (1 <= n3 <= 10^5), the length of the third array.
- The sixth line contains n3 space-separated integers, elements of the third array.
Output format:
- Output a single line of space-separated integers representing the common elements, in sorted order.
Example:
Input:
5
1 2 3 4 5
5
2 3 5 6 7
5
1 2 3 8 9
Output:
2 3
Key concepts
arrayssearch
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