Data Structures & AlgorithmsHardCAT · TCS NQT
Problem: The sum of all integers from 1 to 200 that are divisible by neither 4 nor 7 is what value?
- A. 12942
- B. 12158
- C. 7158
- D. 20100
Correct answer: A. 12942
20100 − 5100 (multiples of 4) − 2842 (multiples of 7) + 784 (multiples of 28) = 12942. Forgetting to add back the multiples of 28 gives 12158, 7158 is the sum of the removed numbers, and 20100 removes nothing.
More Coding Interview Problems questions
- Problem: How many integers from 1 to 100 inclusive are divisible by 7 but not by 14?
- Problem: What is the least common multiple of 6, 8 and 12?
- Problem: How many trailing zeros does 30! have in base 10?
- Problem: How many unordered pairs {x, y} with x ≠ y from the set {1, 2, 3, 4, 5} have x + y even?
- Problem: How many binary strings of length 4 contain no two adjacent 1s?
- Problem: How many two-digit numbers (10–99) have digits that sum to exactly 9?