Data Structures & AlgorithmsVery hard

Why is the maximum product of three values sometimes achieved by two large negatives and one large positive?

  1. A. Products of negatives are always negative.
  2. B. Three positives never have a larger product than two negatives.
  3. C. Two negatives multiply to a positive value, which can exceed the product of the three largest positives when the negatives are large in magnitude.
  4. D. The maximum product must include the smallest value.

Correct answer: C. Two negatives multiply to a positive value, which can exceed the product of the three largest positives when the negatives are large in magnitude.

The product of two negatives is positive, so a pair of large-magnitude negatives times the largest positive can beat the three largest values. Checking both cases gives the answer.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic