Data Structures & AlgorithmsModerateInfosys · Wipro pattern

Two pointers start at both ends of the sorted array [1, 3, 4, 6, 8, 11] to find pairs of DIFFERENT positions with sum 12 (move left if the sum is small, right if it is large, both on a match). How many pairs are found?

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

Correct answer: B. 2

1 + 11 = 12 (match, move both) → 3 + 8 = 11 < 12 → 4 + 8 = 12 (match) → now l and r cross at 6. Pairs: (1, 11) and (4, 8). 6 + 6 would need the same position twice, which is excluded, so '3' is wrong.

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

Exams that ask this topic