Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B

How many index pairs i < j in [1, 2, 3, 4, 5, 6, 7, 8] satisfy (a[i] + a[j]) divisible by 4?

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

Correct answer: A. 6

Group the values by residue mod 4 (two of each residue): pairs with residues 0+0, 2+2 and 1+3 qualify. Summing residues without the grouping makes the count error-prone.

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

Exams that ask this topic