Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Among index pairs i < j of [-8, -3, -1, 2, 5, 9], how many pairs have the minimum possible absolute value of their sum?

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

Correct answer: C. 3

Sort the values and use two pointers to find the minimal absolute sum, then count the pairs that attain it. The minimum absolute sum is 1, reached by (-8, 9), (-3, 2) and (-1, 2), so the count is 3.

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

Exams that ask this topic