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.
Be the first one to answer
Add answer anonymously...
VMware Software Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter