Common Elements in Three Sorted Arrays
Given three sorted arrays A
, B
, and C
of lengths N
, M
, and K
respectively, your task is to find all elements that are present in all three arrays.
Input:
The first line contains an integer 'T', the number of test cases.
For each test case:
The first line contains three space-separated integers 'N', 'M', and 'K'.
The second line contains 'N' space-separated integers, the elements of array 'A'.
The third line contains 'M' space-separated integers, the elements of array 'B'.
The fourth line contains 'K' space-separated integers, the elements of array 'C'.
Output:
For each test case, output the common elements in all three arrays on a single line, separated by spaces.
If no common elements exist, output an empty line.
Example:
Input:
1
4 4 4
2 3 4 7
0 0 3 5
1 3 8 9
Output:
3
Constraints:
1 <= T <= 10
1 <= N, M, K <= 30000
0 <= A[i] <= 10^9
0 <= B[i] <= 10^9
0 <= C[i] <= 10^9
Note:
The output array should maintain the order of elements as they appear in the original arrays.
Each element should appear only once in the output, even if it appears multiple times in the input arrays.
Implement the function without printing anything; the output is handled automatically.

AnswerBot
4mo
Find common elements in three sorted arrays and output them in order.
Iterate through all three arrays simultaneously using three pointers.
Compare elements at pointers and move pointers accordingly.
If ...read more
Help your peers!
Add answer anonymously...
VMware Software Software Developer interview questions & answers
A Software Developer was asked Q. Reverse the String Problem Statement You are given a string STR which contains a...read more
A Software Developer was asked Q. What are the stages in the Software Development Life Cycle?
A Software Developer was asked Q. Common Elements in Three Sorted Arrays Given three sorted arrays A, B, and C of ...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Reverse the String Problem Statement You are given a string STR which contains a...read more
A Software Developer was asked Q2. What are the stages in the Software Development Life Cycle?
A Software Developer was asked Q3. Common Elements in Three Sorted Arrays Given three sorted arrays A, B, and C of ...read more
>
VMware Software Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

