← Quiz: Kadane's Algorithm: all 13 questions
Quiz: Kadane's Algorithm · Question 7 of 13
What does this print? (code)
What does this print?
a = [1, -2, 3]
cur, best = a[0], a[0]
for x in a[1:]:
cur = max(x, cur + x)
best = max(best, cur)
print(cur, end=" ")
- A.-2 3
- B.-1 3
- C.-1 2
- D.1 3
Answer & explanation
Correct answer: -1 3
At −2: max(−2, 1 − 2) = −1. At 3: max(3, −1 + 3) = 3.
Can you get the rest right without peeking?
Take the timed Quiz: Kadane's Algorithm quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →