Question DSA-REC-0061
HardWhat is the output of this code?
def combos(cands, target):
res = []
def go(i, t, path):
if t == 0:
res.append(path[:]); return
for j in range(i, len(cands)):
if cands[j] > t:
break
path.append(cands[j]); go(j, t - cands[j], path); path.pop()
go(0, target, [])
return res
print(combos([2, 3, 6, 7], 7))
- A.
[[7]]
- B.
[[2, 5], [7]]
- C.
Sign up free to see the answer and a step-by-step explanation.