Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.

  1. A. 12
  2. B. 36
  3. C. 78
  4. D. 24

Correct answer: D. 24

Each residue class mod 4 has 3 numbers, giving C(3,2) + 3 = 6 pairs with a ≤ b, so 4 · 6 = 24. Excluding a = b gives 12, ordered pairs give 36, and 78 counts all pairs a ≤ b.

More Coding Interview Problems questions

Exams that ask this topic