Two test case are give me TLE why and this is my code

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0) {
int n=sc.nextInt();
HashMap<Integer,Boolean> map=new HashMap<>();
for(int i=0;i<n;i++) {
map.put(sc.nextInt(),true);
}
int q=sc.nextInt();
while(q!=0) {
int val=sc.nextInt();
if(map.containsKey(val)) {
System.out.println(“Yes”);
}else {
System.out.println(“No”);
}
q–;
}
t–;
}
}

@sksumitkumardiwaker,

https://ide.codingblocks.com/s/234578 corrected code.

Your logic is correct but for every query you are creating a new HashMap and traversing the array again.
Hence for Q queries and N elements in the array your code had the complexity of O(Q*N) or O(N^2).

Instead just create the hashmap once before the queries and print your answer for each query.