It is difficult for me to understand the time complexity of my solution for the combination sum problem. The problem is as follows:

For a number of candidate numbers (

`candidates`

) (without duplicates) and a target number (`target`

) you will find all unique combinations in candidates, in which the candidate numbers add up`target`

,The same number of repetitions can be selected from the candidates an unlimited number of times.

Below is my solution in Java with recursion:

`public List`> combinationSum(int() candidates, int target) {
Arrays.sort(candidates);
List> results = new ArrayList<>();
recurse(results, candidates, target, 0, new ArrayList<>());
return results;
}
private void recurse(List> results, int() candidates, int target, int idx, List acc) {
if (target == 0) {
results.add(new ArrayList<>(acc));
return;
}
for (int i = idx; i < candidates.length; i++) {
if (candidates(i) > target) {
return;
}
acc.add(candidates(i));
recurse(results, candidates, target - candidates(i), i, acc);
acc.remove(acc.size() - 1);
}
}

It can be seen that the problem size of each recursive step may not change and the depth of the recursion is bound by `target`

Value, e.g. if the `candidates`

Array contains number 1 The recursion will take place `target`

times. If I simplify the code, the interesting part is:

`private void recurse(List`> results, int() candidates, int target, int idx, List acc) {
if (target == 0) {
results.add(new ArrayList<>(acc));
return;
}
for (int i = idx; i < candidates.length; i++) {
acc.add(candidates(i));
recurse(results, candidates, target - candidates(i), i, acc);
acc.remove(acc.size() - 1);
}
}

Which feels like `O(candidates.length * target)`

for the most pessimistic `candidates`

Entry with number 1.

Since my solution is not really a divide and conquer algorithm, I probably cannot apply the main clause. It feels like a backtracking algorithm, but I'm not familiar with finding the upper limit for these types of algorithms.

Can someone please advise how to do the complexity analysis of the code above?