Data Structures & AlgorithmsModerateTCS NQT · two pointers

Problem: What property of an array makes the two-pointer technique for pair sums valid?

  1. A. The array has no duplicates
  2. B. The array is sorted
  3. C. The array is a permutation
  4. D. The array is positive

Correct answer: B. The array is sorted

On a sorted array, moving the left or right pointer changes the sum monotonically, which lets the search skip values.

More Coding Interview Problems questions

Exams that ask this topic