Data Structures & AlgorithmsHardTCS NQT · CAT
Problem: The number of integers from 1 to 100 that have exactly three divisors is what value? (Numbers with exactly three divisors are squares of primes.)
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
A number has exactly three divisors precisely when it is the square of a prime. The squares of primes up to 100 are 4, 9, 25, 49 for primes 2, 3, 5, 7, so the count is four.
More Coding Interview Problems questions
- Problem: What is the number of inversions in the array [4, 3, 2, 1, 0]?
- Problem: The string "cabbage" is sorted by letter using a stable sort on the letters only. What is the 4th character of the sorted string?
- Problem: Starting with 1, the operations are: multiply by 2, then add 3, applied three times in a row (x → 2x + 3). What is the result…
- 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…
- 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…