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

Sorted positive array [1, 3, 4, 6, 9, 12]. How many index pairs i < j have a[i] * a[j] >= 18?

  1. A. 12
  2. B. 8
  3. C. 9
  4. D. 6

Correct answer: C. 9

Two pointers on the sorted array: pairs with product ≥ 18 are (3,6), (3,9), (3,12), (4,6), (4,9), (4,12), (6,9), (6,12), (9,12) → 9. Using > 18 drops (3, 6) (8), counting the complement gives 6, and starting j at i adds 6·6, 9·9, 12·12 (12).

More Coding Interview Problems questions

Exams that ask this topic