From 30df94d2ee06770f8589d1ea3cef8b2966f30b56 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Sat, 31 Jan 2026 12:51:06 -0600 Subject: [PATCH] Completed --- Solutions.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Solutions.py diff --git a/Solutions.py b/Solutions.py new file mode 100644 index 00000000..02e97b72 --- /dev/null +++ b/Solutions.py @@ -0,0 +1,42 @@ +## Problem1 Combination Sum (https://leetcode.com/problems/combination-sum/) +## Time Complexity : O(n * 2^(m+n)) +## Space Complexity : O(n^2) + +class Solution(object): + def combinationSum(self, candidates, target): + """ + :type candidates: List[int] + :type target: int + :rtype: List[List[int]] + """ + ## backtracking approach: + ## - I cab either choose or not choose + ## - If choosing adding it to the sum and recurssing + ## - not choosing and recurssing again. + + output = [] + def helper(idx,sm,path): + ## boundary conditions - if out of bounds + if sm > target or idx >= len(candidates): + return + ## base condition -- if sum reached the target + if sm == target: + output.append(path[:]) + return + + path.append(candidates[idx]) + helper(idx,sm+candidates[idx],path) + path.pop() + helper(idx+1,sm,path) + + helper(0,0,[]) + return output + + + + + +## Problem2 Expression Add Operators(https://leetcode.com/problems/expression-add-operators/) +## Time Complexity : +## Space Complexity : +