Challenges hasing and tries

mycode is giving TLE…sir how can i improve it…

package chall_Hashing_and_trees;
import java.util.*;
public class exist_or_not {
static Scanner s=new Scanner(System.in);
public static void main(String[] args) {
int t = s.nextInt();
for(int j=0 ; j<t ;j++) {
int len=s.nextInt();
int[] arr=new int[len];

for(int i=0 ;i<len ;i++) {
arr[i] =s.nextInt();
}

ArrayList list =new ArrayList<>();
for(int i = 0 ;i < len ;i++) {
list.add(arr[i]);
}

int testcase =s.nextInt();
int[] tc=new int[testcase];
for(int i = 0;i<testcase ;i++) {

tc[i] =s.nextInt();

}
for(int i = 0 ; i<testcase ;i++) {
int num = tc[i];
if(list.contains(num)) {
System.out.println(“Yes”);
}else {
System.out.println(“No”);
}
}

}

}

}

hey @sameeksha
This one is a pretty simple problem all we need to do is create a hashmap instead of Arraylist . HashMap contains all the elements present in the array. Then for each query check if the hashmap contains the element then we will print Yes otherwise print No. The checking of element from the hashmap will be done in O(1) so for answering Q queries time complexity required will be O(Q)