Data Structures & AlgorithmsVery hard

How many index pairs i < j in [5, 1, 9, 4, 8, 3, 7] satisfy T[i] − T[j] = 4?

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

Correct answer: B. 1

The order of the pair matters: the earlier element minus the later one must be exactly K. Checking the reverse difference, or the absolute value, admits pairs that the condition rejects.

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

Exams that ask this topic