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

Sorted array [1, 2, 2, 3, 5, 5, 6, 8]. How many index pairs i < j have 6 <= a[i] + a[j] <= 8?

  1. A. 13
  2. B. 10
  3. C. 11
  4. D. 5

Correct answer: C. 11

Count pairs with sum at most 8 and subtract pairs with sum at most 5. Each count is a linear two-pointer pass over the sorted array, and duplicates are counted by index, not by value.

More Coding Interview Problems questions

Exams that ask this topic