Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
int n = sc.nextInt();
int x = sc.nextInt();
ArrayList<Long> al = new ArrayList<>();
for(int i=0;i<n;i++){
al.add(sc.nextLong());
}
Collections.sort(al);
int count=0;
for(int i=1;i<al.size();){
if(al.get(i)==al.get(i-1)){
count++;
al.remove(i);
}else i++;
}
if(count>=x) System.out.println(al.size());
else {
x=x-count;
if(x>=al.size()) System.out.println(0);
else{
System.out.println(al.size()-x);
}
}
t--;
}
Please Can anyone tell me the error in above code it seems to be giving right answers