Data Structures & AlgorithmsHardProduct Company SDE · sorting OA

Problem: What is the maximum product of three numbers in [-10, -10, 5, 2]? Run the code.

Problem: What is the maximum product of three numbers in [-10, -10, 5, 2]? Run the code.
a = sorted([-10, -10, 5, 2])
print(max(a[-1] * a[-2] * a[-3], a[0] * a[1] * a[-1]))
What is printed?
  1. A. 100
  2. B. -90
  3. C. 500
  4. D. 20

Correct answer: C. 500

The three largest values give 5 * 2 * (-10) = -100, while the two most negative numbers times the largest give (-10) * (-10) * 5 = 500.

More Coding Interview Problems questions

Exams that ask this topic