What is problem in this code

import java.util.*;
public class Main {
static HashMap<Integer,Integer> a=new HashMap<>();
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0) {
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
subSet(arr,0,n-1,0);

if(a.get(0)>0) {
	System.out.println("Yes");
}else {
	System.out.println("No");
}
  t--;}
}

private static void subSet(int[] arr, int i, int j,int ans) {
if(i>j) {
	if(ans==0) {
		if(a.containsKey(0)) {
			a.put(0, a.get(0)+1);
		}else {
		a.put(0, 0);
		}
		
	}
	return;
}
subSet(arr, i+1,j,ans);
subSet(arr,i+1,j,ans+arr[i]);

}

}

@sksumitkumardiwaker,

https://ide.codingblocks.com/s/224766 Corrected code.

Your logic is correct. You are using the same hashmap for all your test cases. Hence the error. You need a blank hashmap for every test case. Hence either pass it as an argument or reset it before calling subSet method.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.