Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT

Problem: What is the sum of all prime numbers less than 30?

  1. A. 127
  2. B. 130
  3. C. 129
  4. D. 100

Correct answer: C. 129

2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 = 129. Leaving out 2 gives 127, counting 1 as prime gives 130, and stopping below 29 gives 100.

More Coding Interview Problems questions

Exams that ask this topic