Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Among pairs of distinct elements of [-8, -3, 1, 5, 9, 12], which pair sum is closest to the target 4? (Report the sum itself.)

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

Correct answer: D. 4

The pair -8 and 12 sums to exactly 4, the target, so the closest achievable sum is 4. Two pointers on the sorted array would find it.

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

Exams that ask this topic