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).
- A. 8
- B. 16
- C. 9
- 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
- Problem: The string "abcabcabcabc" is split into consecutive chunks of length 5 from the left (the last chunk may be shorter). How many…
- Problem: A binary search tree is built from the values 15, 10, 20, 8, 12, 17, 25 inserted in that order. What is the number of leaves…
- Problem: A stack-based simulation begins with an empty stack. Operations in order: push 4, push 7, push 2, pop, push 9, pop, push 5. What…
- Problem: A tree on 5 nodes is given by edges 1-2, 2-3, 2-4, 4-5. The diameter (in edges) of this tree is what value?
- Problem: A sequence is defined by s(1) = 1, s(2) = 2, and s(n) = s(n−1) + s(n−2) for n ≥ 3. What is the remainder when s(12) is divided by…
- Problem: How many subsets of {1, 2, 3, 4, 5, 6} contain exactly two odd numbers?