Data Structures & AlgorithmsVery hardTCS NQT · Infosys

In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i] - a[j]| = d?

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

Correct answer: B. 2

After sorting, the minimum gap is 2 (6 to 8 and 4 to 6), so the pairs are counted by checking adjacent sorted values.

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

Exams that ask this topic