class Solution {
// functions to fine the combinations
private void findCombinations(int ind, int arr[], int target,
List<List<Integer>> ans, List<Integer> ds)
{
// check weather arr length and index equal or not
if(ind==[Link]){
if(target==0)
{
[Link](new ArrayList<>(ds));
}
return;
}
// check the current index element of array is less equal to target or not
if(arr[ind]<= target){
// add element into the arraylist
[Link](arr[ind]);
// do recursive call for the same index element
findCombinations(ind, arr, target-arr[ind],ans, ds);
// remove last inserted element from the array list
[Link]([Link]()-1);
}
// do recursive call for the next index element
findCombinations(ind+1, arr, target,ans, ds);
}
public List<List<Integer>> combinationSum(int[] candidates, int target) {
// ans list to storing the answer
List<List<Integer>> ans= new ArrayList<>();
// call the findcombination function
findCombinations(0,candidates,target,ans, new ArrayList<>());
// return the final list
return ans;
}
}