Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT

Problem: Find the number of integers n in the range 2 to 100 for which n and n + 2 are both prime (twin primes, counted by the smaller member).

  1. A. 8
  2. B. 16
  3. C. 9
  4. D. 25

Correct answer: A. 8

Smaller members 3, 5, 11, 17, 29, 41, 59, 71 give 8 twin pairs. Counting both members gives 16, gap-4 (cousin) pairs give 9, and 25 is the count of all primes below 100.

More Coding Interview Problems questions

Exams that ask this topic