🎙 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 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?

  1. A.Because the circle has no start
  2. B.Every number is negative, so total − (minimum subarray) would mean taking no elements at all
  3. C.To avoid a division by zero
  4. 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 →