- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsetSumTarget.py
More file actions
Latest commit
25 lines (15 loc) · 584 Bytes
/
Copy pathsubsetSumTarget.py
File metadata and controls
25 lines (15 loc) · 584 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
importitertools
defremoveLargerNumThanK(n: list, k: int) ->list:
return [iforiinnifi<=k]
defgenerateSubsets(n: list) ->list:
foriinrange(1, len(n)):
forjinitertools.combinations(n, i):
yieldlist(j)
defcheckCondition(sublist: list, k: int) ->bool:
returnsum(sublist) ==k
defcheckSubestSum(n: int, k: int) ->list:
return [iforiingenerateSubsets(n) ifcheckCondition(i, k)]
n=list(map(int, input().split()))
k=int(input())
n=removeLargerNumThanK(n, k)
print(checkSubestSum(n, k))