From 2f12f3093f6bfc7c22754f712bb06a7be0e9b508 Mon Sep 17 00:00:00 2001 From: shantanujoshi25 Date: Sun, 15 Feb 2026 15:50:37 -0800 Subject: [PATCH] Completed --- Problem_1.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Problem_1.py diff --git a/Problem_1.py b/Problem_1.py new file mode 100644 index 00000000..eac60338 --- /dev/null +++ b/Problem_1.py @@ -0,0 +1,28 @@ +# // Time Complexity : O(n^t) +# // Space Complexity : O(t) +class Solution: + + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + self.result = [] + candidates.sort() + self.recurse(candidates,0, target, []) + return self.result + + def recurse(self, candidates,index, target, path): + + if(target < 0): + return + + if(target == 0): + self.result.append(path.copy()) + return + + + for i in range(index,len(candidates)): + if candidates[i] > target: + break + path.append(candidates[i]) + self.recurse(candidates,i, target-candidates[i], path) + path.pop(-1) + +