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 ofARR1
.
- Second line contains 'N' space-separated integers representingARR1
.
- Third line contains an integer 'M', size ofARR2
.
- Fourth line contains 'M' space-separated integers representingARR2
.
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

AnswerBot
1y
The task is to find the intersection of two integer arrays/lists.
Read the number of test cases
For each test case, read the size and elements of the first array/list
Read the size and elements of the se...read more
Himanshu Saini
1y
import java.util.Arrays; public class Solution { public static void intersection(int[] arr1, int[] arr2) { Arrays.sort(arr1); Arrays.sort(arr2); int i=0,j=0; while(i<arr1.length&&j<arr2.length){ if(ar...read more
Bharat Sharma
2y
ex -
import java.util.Set; import java.util.HashMap; public class Solution { public static void intersection(int[] arr1, int[] arr2) { if(arr1.length==0 || arr2.length==0) return ; HashMap<Integer,Integer>...read more
Add answer anonymously...
Meesho Software Developer interview questions & answers
A Software Developer was asked 7mo agoQ. Design a cab booking system (LLD).
A Software Developer was asked 7mo agoQ. How do you implement concurrency?
A Software Developer was asked 9mo agoQ. Lld of cab booking system
Popular interview questions of Software Developer
A Software Developer was asked 7mo agoQ1. Design a cab booking system (LLD).
A Software Developer was asked 7mo agoQ2. How do you implement concurrency?
A Software Developer was asked 9mo agoQ3. Lld of cab booking system
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

