Why i am failing second testcase any one help me?

import java.util.*;
public class Main {

static void exists(int[] a,int[] b){
LinkedHashMap<Integer,String> c = new LinkedHashMap<Integer,String>();

for(int i=0;i<a.length;i++){
c.put(a[i]," ");
}
// System.out.println©;
for(int j=0;j<b.length;j++){

if(c.containsKey(b[j])){
// c.put(b[j],“Yes”);
System.out.println(“Yes”);
}
else{
System.out.println(“No”);
}

}

// for (Map.Entry<Integer, String> entry : c.entrySet()) {
// if(entry.getValue() == “Yes” || entry.getValue() == “No”)
// System.out.println(entry.getValue());
// }
// return “No”;
}

public static void main(String args[]) {
Main l = new Main();
Scanner sc = new Scanner(System.in);
long tc = sc.nextInt();
while(tc–>0){
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
int m = sc.nextInt();
int[] b = new int[m];
for(int j=0;j<m;j++){
b[j] = sc.nextInt();
}
l.exists(a,b);

}

}

}

HI @indrajeetbhattacharya5

Please paste your code in ide.codingblocks.com and save it. Then send the link of the code here.


Here is the code

HI @indrajeetbhattacharya5

I made the required changes to your code. Should work for all the test cases now.

import java.util.*;

public class Main {

public static void main(String args[]) {
Main l = new Main();
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while (tc-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
HashMap<Integer, Integer> c = new HashMap<>();

		for (int i = 0; i < a.length; i++) {
			c.put(a[i], a[i]);
		}
		int m = sc.nextInt();
		
		for (int j = 0; j < m; j++) {
			if (c.containsKey(sc.nextInt())) {

				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		
	}
}

}

1 Like

Thank you very much for the answer