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

Sorted array [1, 2, 7, 8, 11, 15]. How many index triples i < j < k satisfy a[i] + a[j] + a[k] = 18?

  1. A. 2
  2. B. 0
  3. C. 1
  4. D. 3

Correct answer: C. 1

Fix the smallest element and use two pointers over the remaining sorted suffix to find pairs with the required sum; each match is one triple. Sum 17 is a neighbouring target that changes the count.

More Coding Interview Problems questions

Exams that ask this topic