Array Intersection Problem Statement

Given two integer arrays/ lists ARR1 and ARR2 of sizes N and M respectively, you are required to determine their intersection. An intersection is defined as the set of common values existing in both arrays/lists.

Note:
- Input arrays/lists can contain duplicate elements.
- The intersection elements should be printed in the order they appear in the first array/list ARR1.

Input:

First line contains an integer 't' indicating the number of test cases. 
For each test case:
- First line contains an integer 'N', size of ARR1.
- Second line contains 'N' space-separated integers representing ARR1.
- Third line contains an integer 'M', size of ARR2.
- Fourth line contains 'M' space-separated integers representing ARR2.

Output:

For each test case, output the intersection elements as a single line, separated by spaces.
Print a separate line for each test case.

Example:

Input:
2
4
1 2 2 3
3
2 3 4
5
1 2 2 3 4
3
2 2 5
Output:
2 3
2 2

Constraints:

  • 1 ≤ t ≤ 10^2
  • 0 ≤ N ≤ 10^5
  • 0 ≤ M ≤ 10^5
  • Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Optum 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