Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many unordered index pairs i < j in the sorted array [1, 3, 4, 6, 8, 9, 11] satisfy a[i] + a[j] = 12?

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

Correct answer: A. 3

The pairs summing to 12 are (1, 11), (3, 9), (4, 8). The two-pointer scan finds each in one pass.

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

Exams that ask this topic