Sum it Up : 1 Test case failed

Kindly have a look at the code.

hi @mananaroramail
send me your code link some other IDE this one is not working

https://ide.geeksforgeeks.org/hXXIedA8Rz

@mananaroramail
to remove duplicates you have to check the previous element as there will be duplicacy because of the similar characters.
if (i == last_idx+1 || arr[i] != arr[i - 1]) {
curr.add(arr[i]);
helper2(arr, i + 1, target - arr[i], curr, res);
curr.remove(curr.size() - 1);
}

hi @mananaroramail
i have made few changes to your code if you have any doubt feel free to ask

import java.util.*;

public class Main { public static ArrayList list = new ArrayList<>(); public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList arr = new ArrayList<>(); for(int i = 0 ; i<n ; i++) { arr.add(sc.nextInt()); }

Collections.sort(arr);
int target = sc.nextInt();
ArrayList<Integer> helper = new ArrayList<>();
SumItUp(arr , target , -1 , helper);

for( ArrayList<Integer> val : list )
{
	for( Integer ans : val)
	{
		System.out.print(ans + " ");
	}
	System.out.println();
}

}

public static void SumItUp(ArrayList arr , int target , int last_index , ArrayList helper)
{
if( target == 0)
{
list.add(new ArrayList<>(helper));
return;
}
if( target < 0)
{
return;
}

for(int i = last_index + 1 ; i<arr.size() ; i++)
{
	if(i==last_index+1 || arr.get(i)!=arr.get(i-1)){
	helper.add(arr.get(i));
	SumItUp(arr , target - arr.get(i) , i , helper);
	helper.remove(helper.size() - 1);
	}
}

}
}

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.