Question DSA-DP-0012
MediumWhat is the output of this code?
a = [2, 7, 9, 3, 1]
prev = cur = 0
for x in a:
prev, cur = cur, max(cur, prev + x)
print(cur)
- A.
11
- B.
12
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Dynamic Programming question
What is the output of this code?
a = [2, 7, 9, 3, 1]
prev = cur = 0
for x in a:
prev, cur = cur, max(cur, prev + x)
print(cur)
11
12
Sign up free to see the answer and a step-by-step explanation.
10
15