I wrote this code for Challenges - Recursion
Topic :- Subset Sum Easy
import java.util.Scanner;
public class Main {
public static boolean sum(int[] arr){
if(arr.length==0){
return false;
}
int a = arr[0];
int[] subarray = new int[arr.length-1];
int s=0;
for(int i=1;i<arr.length;i++){
subarray[i-1]=arr[i];
s+=subarray[i-1];
}
boolean flag = sum(subarray);
for(int i=0;i<subarray.length;i++){
if(s==0){
if(subarray.length!=0){
flag=true;
}
}else if(subarray[i]+a==0){
flag = true;
}else if(a==0){
flag = true;
}
}
return flag;
}
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
int row=1;
while(row<=t){
int n = scn.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = scn.nextInt();
if(sum(arr)){
System.out.println(“Yes”);
}else{
System.out.println(“No”);
}
row++;
}
}
}
Some of the test cases are coming wrong please tell me how to improve this code to perfect all test cases.