Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Space Complexity: O(h)
# Time Complexity: O(2 ^ n)

class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
ans = []

def rec(i,res):
if i >= len(nums):
ans.append(res[:])
return


rec(i+1,res)

res.append(nums[i])
rec(i+1,res)
res.pop()


rec(0,[])

return ans


40 changes: 40 additions & 0 deletions problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Space Complexity: O(h) -> h can max to s
# Time Complexity: O(2^n)
class Solution:
def partition(self, s: str) -> List[List[str]]:
def pali(s):
i = 0
j = len(s)-1

while i <= j:
if s[i] != s[j]:
return False
i+=1
j-=1
return True

ans = []

def helper(s, pivot, path):
# Base Case
if pivot >= len(s):
ans.append(path[:])
return

# Logic
for i in range(pivot, len(s)):
curr = s[pivot:i+1]
if pali(curr):

#action
path.append(curr)

#recurse
helper(s, i+1, path)

#backtrack
path.pop()


helper(s, 0, [])
return ans