🎙 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 13 of 13

In the maximum product subarray, why swap hi and lo when x is negative?

In the maximum product subarray, why swap hi and lo when x is negative?

  1. A.To keep the array sorted
  2. B.Because negative numbers must be skipped
  3. C.To reset the product to 1
  4. D.Multiplying by a negative number turns the largest product into the smallest and the smallest into the largest
Answer & explanation

Correct answer: Multiplying by a negative number turns the largest product into the smallest and the smallest into the largest

A very negative product times a negative x can become the new maximum.

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 →