Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many integers from 1 to 300 are divisible by 4 or 6 but not by 12?

  1. A. 75
  2. B. 100
  3. C. 125
  4. D. 50

Correct answer: A. 75

Multiples of 4 or 6: 75 + 50 − 25 = 100; removing the 25 multiples of 12 leaves 75. 100 forgets the exclusion, 125 skips inclusion-exclusion, and subtracting the 12s twice gives 50.

More Coding Interview Problems questions

Exams that ask this topic