Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Sorted array b = [1, 2, 3, 4, 5, 7, 8, 9]. What is the largest product b[i] * b[j] over index pairs with j - i >= 3?

  1. A. 36
  2. B. 49
  3. C. 45
  4. D. 72

Correct answer: C. 45

Because the values are sorted, the largest product with an index gap of at least 3 comes from pairing the largest value with the largest value that is at least three positions to its left. Allowing gap 1 gives the unrestricted maximum, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic