Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many ordered index pairs (i, j) in [1, 3, 4, 7, 10, 12, 15] satisfy a[j] - a[i] = 3?

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

Correct answer: B. 4

With distinct sorted values, each value v has at most one partner v + 3, so the count is the number of such matches. Checking membership with two pointers or a set gives the same total.

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

Exams that ask this topic