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 find_combinations(nums, target):
if target == 0:
return [[]]
if target < 0 or not nums:
return []
result = []
for i, num in enumerate(nums):
if i > 0 and nums[i] == nums[i-1]:
continue
if num > target:
break
combinations = find_combinations(nums[i+1:], target - num)
for combo in combinations:
result.append([num] + combo)
return result
nums = [2, 3, 6, 7]
target = 7
combinations = find_combinations(nums, target)
for combo in combinations:
print(combo)
Browse other Product Reviews tagged
[7]
[2, 2, 3]
CONTRIBUTE TO THIS THREAD