Data Structures & AlgorithmsVery hard
Why is the maximum product of three values sometimes achieved by two large negatives and one large positive?
- A. Products of negatives are always negative.
- B. Three positives never have a larger product than two negatives.
- 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.
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For a binary string with no three equal consecutive bits, why is a run-length description convenient for counting?
- Why does the sliding-window approach fail to find the shortest subarray with sum divisible by m when values are NEGATIVE?
- Which property makes the ordered-pair count of A[i] > A[j] equal to the number of unequal unordered pairs?
- When an array's values are all distinct, what is the number of ordered pairs (i, j), i ≠ j, with A[i] > A[j]?
- Push and pop operations on an initially empty stack are: push, push, pop, push, push, push, pop, pop, push. What is the maximum height the…
- Customers arrive at times 0, 1, 2 and 5 and need service times 3, 2, 1 and 2 on a single server (first come, first served; a customer…