# Given an array, print all unique subsets with a given sum.

**Objective: **Given an array of integers and number N, Write an algorithm to find and print all the subsets of the array for which sum is equal to N.

**Example**:

input [] = {6,2,7,8,2,4,1,3,7,5} Sum = 8 Output: [1, 2, 2, 3] [1, 2, 5] [1, 3, 4] [1, 7] [2, 2, 4] [2, 6] [3, 5] [8] input [] = {1,2,3,4,5,6}; Sum = 6 [1, 2, 3] [1, 5] [2, 4] [6]

**Approach: Use Recursion**

- Given
and*arrA[]*.*sum* - Sort the
in ascending order.*arrA[]* - Start with
= 0,*currSum*= 0,*start*=null*combinationList* - Iterate through
=*i*to*start*.*length(arrA[])*- Add
to*arrA[i]*.*currSum* - Put
to*arrA[i]**combinationList.* - Make a recursive call with
(to process next elements) and*start = start + 1**combinationList.* - In tail recursion, backtrack and remove
from the*arrA[i]*to find more solutions*combinationList* - Base case: if
*currSum=sum*.*combinationList* - During iteration, if the current element is the same as the previous element then skip the current element. (this step is required to avoid duplicate results in case array has duplicate elements, sorting will bring them together so skip one of the element, for example, array is [1, 1, 4], sum = 5, then the results would be [1, 4] and [1, 4] if we use both the 1’s but it produces identical results, so consider only one element.)

- Add

**Complete Code:**

**Output:**

Given Array: [6, 2, 7, 8, 2, 4, 1, 3, 7, 5], required sum: 8 [1, 2, 2, 3] [1, 2, 5] [1, 3, 4] [1, 7] [2, 2, 4] [2, 6] [3, 5] [8]