Data Structures & AlgorithmsHardTCS NQT · counting

Problem: How many integers from 1 to 1000 are divisible by 3 or by 5 but not by both?

  1. A. 467
  2. B. 401
  3. C. 533
  4. D. 400

Correct answer: B. 401

Multiples of 3 or 5 number 333 + 200 - 66 = 467, and removing the 66 multiples of 15 (divisible by both) leaves 401. Forgetting to remove the overlap gives the trap 467.

More Coding Interview Problems questions

Exams that ask this topic