🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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=" ")
  1. A.-2 3
  2. B.-1 3
  3. C.-1 2
  4. 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 →