Coding Challenges < Python >

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)
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)
Solution:
[7] [2, 2, 3]...
Jump to solution
2 Replies
Soumayukii
Soumayukii8mo ago
7
Solution
Camila_99$$
Camila_99$$8mo ago
[7] [2, 2, 3]
Want results from more Discord servers?
Add your server