Skip to content

Commit

Permalink
Create Find missing in second array
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Apr 19, 2024
1 parent ae476d4 commit 251c267
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Find missing in second array
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//Find missing in second array

import java.io.*;
import java.util.*;

class Solution {
ArrayList<Integer> findMissing(int a[], int b[], int n, int m) {
ArrayList<Integer> ans = new ArrayList<>();
Map<Integer, Integer> map = new HashMap<>();

for(int elb : b) {
map.put(elb, 1);
}

for(int ela : a) {
if(!map.containsKey(ela)) {
ans.add(ela);
}
}

return ans;
}
}

class Array {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcases = Integer.parseInt(br.readLine());

while(testcases-- > 0) {
String line = br.readLine();
String[] q = line.trim().split("\\s+");
int n =Integer.parseInt(q[0]);
int m =Integer.parseInt(q[1]);
String line1 = br.readLine();
String[] a1 = line1.trim().split("\\s+");
int a[] = new int[n];

for(int i = 0; i < n; i++) {
a[i] = Integer.parseInt(a1[i]);
}

String line2 = br.readLine();
String[] a2 = line2.trim().split("\\s+");
int b[] = new int[m];

for(int i = 0; i < m; i++) {
b[i] = Integer.parseInt(a2[i]);
}

Solution ob = new Solution();
ArrayList<Integer> ans=ob.findMissing(a,b,n,m);

for(int i = 0; i < ans.size(); i++) {
System.out.print(ans.get(i)+" ");
}
System.out.println();
}
}

0 comments on commit 251c267

Please sign in to comment.