Intersection of Two Unsorted Arrays Problem Statement
Given two integer arrays ARR1
and ARR2
of sizes 'N' and 'M' respectively, find the intersection of these arrays. The intersection is defined as the set of elements common to both arrays. The result should maintain the order as they appear in ARR1
.
Note:
The input arrays can contain duplicate elements, and the intersection result should preserve order based on ARR1
.
Input:
The first line contains an integer 't', which denotes the number of test cases. The next lines describe the test cases:
- For each test case:
- First line: an integer 'N' (size ofARR1
)
- Second line: 'N' space-separated integers (elements ofARR1
)
- Third line: an integer 'M' (size ofARR2
)
- Fourth line: 'M' space-separated integers (elements ofARR2
)
Output:
For each test case, output the intersection elements in one line, separated by a single space. Print each result for a test case on a separate line.
Example:
Input:
1
5
1 2 2 3 4
4
2 2 4 6
Output:
2 2 4
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...
Top Practo Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Practo Software Developer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app