Dsa
Two Pointers
Easy
Common Elements in K Sorted Arrays
You are given k sorted arrays of integers. Your task is to find the common elements that appear in all k arrays. Use a two-pointer technique to traverse through the arrays efficiently.
Input Format:
- The first line contains an integer k, the number of arrays.
- The next k lines each contain a sorted array of integers, separated by spaces.
Output Format:
- Print the common elements in sorted order, space-separated.
Example:
Input:
3
1 2 3 4
2 3 4 5
2 4 6
Output:
2
Key concepts
two_pointersarrayssorting
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