Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many index pairs i < j in [1, 4, 6, 9, 10, 12] satisfy a[i] + a[j] >= 15?

  1. A. 6
  2. B. 15
  3. C. 7
  4. D. 4

Correct answer: C. 7

On the sorted array each left index pairs with a suffix: (4,12), (6,9), (6,10), (6,12), (9,10), (9,12), (10,12) = 7. Using > 15 drops (6,9) and gives 6, 15 counts all pairs, and 4 counts only the pairs with 12.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic