Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT
Problem: How many prime numbers are there up to 100 (inclusive)?
- A. 26
- B. 24
- C. 25
- D. 168
Correct answer: C. 25
A sieve up to 100 leaves 25 primes, from 2 to 97. Counting 1 as prime gives 26, counting only odd primes gives 24, and 168 is the count up to 1000.
More Coding Interview Problems questions
- Problem: What is the LCM of the array [4, 6, 10, 15]?
- Problem: Count the pairs (i, j) with i < j in the array [1, 2, ..., 10] whose sum is divisible by 4.
- Problem: Find the majority element (appearing more than half the time) of [2, 2, 1, 1, 1, 2, 2] using the Boyer–Moore voting algorithm…
- Problem: Kadane's algorithm finds the maximum sum of a non-empty contiguous subarray of [−2, 1, −3, 4, −1, 2, 1, −5, 4]. What is that…
- Problem: The array [1, 2, 3, 4, 5, 6, 7] is rotated right by 3 positions (the last 3 elements move to the front). What is the element at…
- Problem: Merging two sorted lists [1, 4, 7] and [2, 3, 8, 9] with the standard two-pointer merge, how many element comparisons are made in…