Question DSA-DP-0048
MediumWhat is the output of this code?
def rob(a):
take, skip = 0, 0
for x in a:
take, skip = skip + x, max(take, skip)
return max(take, skip)
print(rob([2, 7, 9, 3, 1]))
- A.
12
- B.
10
- C.
Sign up free to see the answer and a step-by-step explanation.