ProgrammingHardTCS NQT · Infosys

In the sorted array {1, 2, 4, 6, 8, 9}, how many unordered pairs of distinct elements sum to 17?

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

Correct answer: D. 1

Only (8, 9) sums to 17; 9 needs 8 and every other element needs a partner (above 9) that is not present. A two-pointer scan from both ends finds it in linear time.

More C Programming questions

Exams that ask this topic