Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT
Problem: What is the sum of all prime numbers less than 30?
- A. 127
- B. 130
- C. 129
- 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
- Problem: How many bits are needed to write 10^9 in binary (the number of bits in its binary representation)?
- Problem: Reverse the 8-bit binary representation of 13 (00001101) and report the resulting unsigned value in decimal.
- Problem: What is the smallest positive integer x such that 1 + 2 + … + x is at least 100?
- Problem: How many composite numbers lie in the range 2 to 50 (inclusive)?
- Problem: How many integers x with 0 ≤ x ≤ 99 satisfy x³ ≡ x (mod 7)?
- Problem: Daily temperatures are [73, 74, 75, 71, 69, 72, 76, 73]. For each day, the wait is the number of days until a strictly warmer day…