← Quiz: Kadane's Algorithm: all 13 questions
Quiz: Kadane's Algorithm · Question 2 of 13
In Kadane's algorithm, when does the current subarray "restart" at x?
In Kadane's algorithm, when does the current subarray "restart" at x?
- A.When x is negative
- B.When the running sum before x is negative, so x alone is bigger than cur + x
- C.Every time best improves
- D.Never — it always extends
Answer & explanation
Correct answer: When the running sum before x is negative, so x alone is bigger than cur + x
cur + x < x exactly when cur < 0: a negative running sum can only make things worse.
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 →