Data Structures & AlgorithmsHard

How many index pairs i < j in 2 5 3 9 4 7 6 satisfy A[i] < A[j] AND (A[j] − A[i]) divides (j − i)?

  1. A. 15
  2. B. 6
  3. C. 7
  4. D. 8

Correct answer: C. 7

The divisibility is of the index gap by the value difference, which is a non-trivial pairing test. Reversing the divisibility, dropping the increasing condition, or shifting the count changes the answer.

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

Exams that ask this topic