Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many integers n with 1 ≤ n ≤ 500 satisfy n mod 3 = n mod 5 ?

  1. A. 68
  2. B. 100
  3. C. 102
  4. D. 101

Correct answer: D. 101

n mod 3 = n mod 5 exactly when n mod 15 ∈ {0, 1, 2}; there are 33 full blocks of 15 (99 values) plus 496 and 497, so 101. Forgetting residue 0 gives 68, the estimate 500 × 3 / 15 gives 100, and starting the count at n = 0 gives 102.

More Coding Interview Problems questions

Exams that ask this topic