Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: The set S = {1, 2, 3, …, 30} is considered. How many integers in S are NOT divisible by 2, 3 or 5?
- A. 10
- B. 22
- C. 8
- D. 15
Correct answer: C. 8
The numbers 1, 7, 11, 13, 17, 19, 23, 29 avoid 2, 3, 5, so φ(30) = 8. Ignoring 5 gives 10, the complement gives 22, and 15 counts only odd numbers.
More Coding Interview Problems questions
- Problem: A binary search over the sorted array [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] looks for the value 12 which is absent. Using the…
- Problem: The 10 numbers 1 to 10 are split into two groups of five. The sum of the group containing 10 is S. How many different values of S…
- Problem: In a directed acyclic graph with arcs 0→1, 0→2, 1→3, 2→3, 3→4, 2→4, how many distinct topological orders exist?
- Problem: Compute the number of trailing zeros of 25! in base 5 (that is, how many times 5 divides 25!).
- Problem: A stack starts with the characters pushed in the order a, b, c, d. The following pops occur: pop, pop, then push e, pop. Which…
- Problem: The grid 2×3 contains the values [[1,2,3],[4,5,6]]. From the top-left cell you move right or down to the bottom-right, collecting…