Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
What will be the output of this code?
def count_subsets(nums, target):
memo = {}
def backtrack(index, remaining):
if (index, remaining) in memo:
return memo[(index, remaining)]
if remaining == 0:
return 1
if remaining < 0 or index == len(nums):
return 0
count = backtrack(index + 1, remaining - nums[index]) + backtrack(index + 1, remaining)
memo[(index, remaining)] = count
return count
return backtrack(0, target)
nums = [1, 2, 3, 4, 5]
target = 7
print(count_subsets(nums, target))
Browse other Product Reviews tagged
CONTRIBUTE TO THIS THREAD