Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT
Problem: How many prime numbers are there in the range 1 to 200 (inclusive)?
- A. 47
- B. 46
- C. 45
- D. 25
Correct answer: B. 46
A sieve up to 200 leaves 46 primes (25 of them up to 100, 21 between 101 and 199). Counting 1 as prime gives 47, counting only odd primes gives 45, and 25 is the count up to 100.
More Coding Interview Problems questions
- Problem: Compute σ(360), the sum of all positive divisors of 360.
- Problem: The gas-station problem: gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2] around a circular route of 5 stations, starting with an…
- Problem: Children with greed factors g = [1, 2, 3] and cookies s = [1, 1] (each child takes at most one cookie, and a cookie of size ≥ the…
- Problem: Balloons are shot with arrows that burst every balloon whose horizontal interval contains the arrow's x position. Intervals are…
- Problem: A stream of integers arrives: 4, 9, 1, 7, 8, 3, 6. After each arrival from the 2nd onwards, we report the 2nd largest value seen…
- Problem: How many binary search trees can be formed with exactly 5 distinct keys?