Hello, I am trying to understand why my solution to combinatorial sum II does not work for a a few specific test cases. Specifically. when the input is [2,4,2,5,2]
5, my function outputs an empty list instead of an list including [5]. To summarize the problem: you should return all lists containing combinations that sum up to the provided target (in this case 5). Thank you!
class Solution:
def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
def helper(candidates, target, sum_track, combo, combo_list):
if sum_track > target:
return
if sum_track == target:
if sorted(combo) not in combo_list:
combo_list.append(sorted(combo))
return
for i in range(len(candidates)):
temp = candidates[i]
candidates.remove(temp)
combo.append(temp)
helper(candidates, target, sum_track + temp, [x for x in combo], combo_list)
candidates.insert(i, temp)
combo.pop()
sum_track = 0
combo = []
combo_list = []
helper(candidates, target, sum_track, combo, combo_list)
return combo_list
` ` `