Created
May 21, 2021 15:05
-
-
Save prasadwrites/9bfcdec4bb049cb924e022b5cff7bb92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr=[5,4,8, 10,-4] | |
k=6 | |
def check_if_sum_possible(arr, k): | |
slate = [] | |
index = 0 | |
arrlen = 0 | |
if arr: | |
arrlen = len(arr) | |
def printSubset(index, slate): | |
#base case | |
if(index==arrlen): | |
sum = 0 | |
if slate: | |
for i in range(len(slate)): | |
sum = sum + slate[i] | |
if sum == k: | |
print(slate, end=" ") | |
return True | |
else: | |
return False | |
return | |
else: | |
return False | |
if(printSubset(index+1,slate)): | |
return True | |
slate.append(arr[index]) | |
if(printSubset(index+1,slate)): | |
return True | |
slate.pop() | |
if(printSubset(index,slate)): | |
return True | |
return False | |
print(check_if_sum_possible(arr, k)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment