Data Structures & AlgorithmsHard

How many index pairs i < j in 4 1 7 2 10 5 8 satisfy A[i] ≡ A[j] (mod 3) AND A[i] < A[j]?

  1. A. 8
  2. B. 9
  3. C. 15
  4. D. 1

Correct answer: A. 8

Both the residue equality and the increasing order must hold for the same pair in index order. Dropping either condition, or reversing the comparison, changes the count.

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

Exams that ask this topic