Skip to content

Commit 57bed48

Browse files
Update sum_of_subsets.py
1 parent 91ad9c6 commit 57bed48

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

backtracking/sum_of_subsets.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ def generate_sum_of_subsets_solutions(nums: list[int], max_sum: int) -> list[lis
1212
"""
1313
The main function. For list of numbers 'nums' find the subsets with sum
1414
equal to 'max_sum'
15-
>>> generate_sum_of_subsets_solutions([3, 34, 4, 12, 5, 2], 9)
15+
16+
>>> generate_sum_of_subsets_solutions(nums=[3, 34, 4, 12, 5, 2], max_sum=9)
1617
[[3, 4, 2], [4, 5]]
17-
>>> generate_sum_of_subsets_solutions([3, 34, 4, 12, 5, 2], 3)
18+
>>> generate_sum_of_subsets_solutions(nums=[3, 34, 4, 12, 5, 2], max_sum=3)
1819
[[3]]
19-
>>> generate_sum_of_subsets_solutions([3, 34, 4, 12, 5, 2], 1)
20+
>>> generate_sum_of_subsets_solutions(nums=[3, 34, 4, 12, 5, 2], max_sum=1)
2021
[]
2122
"""
2223

@@ -43,7 +44,13 @@ def create_state_space_tree(
4344
This algorithm follows depth-fist-search and backtracks when the node is not
4445
branchable.
4546
46-
>>> create_state_space_tree([1], 1, 0, [], [], 1)
47+
>>> path = []
48+
>>> result = []
49+
>>> create_state_space_tree(nums=[1], max_sum=1, num_index=0, path=path, result=result, remaining_nums_sum=1)
50+
>>> path
51+
[]
52+
>>> result
53+
[]
4754
"""
4855

4956
if sum(path) > max_sum or (remaining_nums_sum + sum(path)) < max_sum:

0 commit comments

Comments
 (0)