← Quiz: Kadane's Algorithm: all 13 questions
Quiz: Kadane's Algorithm · Question 12 of 13
In the maximum circular subarray code, why return bestmax when it is negative?
In the maximum circular subarray code, why return best_max when it is negative?
- A.Because the circle has no start
- B.Every number is negative, so total − (minimum subarray) would mean taking no elements at all
- C.To avoid a division by zero
- D.Because the minimum subarray is then positive
Answer & explanation
Correct answer: Every number is negative, so total − (minimum subarray) would mean taking no elements at all
If every number is negative, the minimum subarray is the whole array, and total − total = 0 would stand for an empty subarray.
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 →