← 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?
- A.To keep the array sorted
- B.Because negative numbers must be skipped
- C.To reset the product to 1
- 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 →