text function combinationSum(candidates, target): result = [] backtrack(candidates, target, 0, [], result) return result function backtrack(candidates, remaining, start, current, result): if remaining == 0: result.append(copy of current) return if remaining < 0: return for i from start to length(candidates) - 1: current.append(candidates[i]) backtrack(candidates, remaining - candidates[i], i, current, result) current.pop() Time complexity: in worst case. Space complexity: recursion depth.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/backtracking/combination-sum-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████████