Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: Count integers from 1 to 100 that are divisible by 3 or by 5 but not by 15.
- A. 47
- B. 53
- C. 35
- D. 41
Correct answer: D. 41
33 multiples of 3 plus 20 of 5 count the 6 multiples of 15 twice, and those must be excluded entirely: 33 + 20 − 2·6 = 41. Plain inclusion–exclusion (3 or 5) gives 47, forgetting the overlap gives 53, and subtracting the 15s three times gives 35.
More Coding Interview Problems questions
- Problem: Compute 2^(2^5) mod 1000 (that is, 2 raised to the power 32, taken modulo 1000).
- Problem: With coin denominations 1, 7 and 10, what is the minimum number of coins needed to make 97?
- Problem: Job sequencing: five jobs (deadline, profit) are (2, 100), (1, 19), (2, 27), (1, 25), (3, 15). Each job takes one unit of time…
- Problem: Boats carry at most 2 people and a weight limit of 10 per boat. Four people weigh 3, 5, 3 and 4. What is the minimum number of…
- Problem: What is the smallest integer x with x·x ≥ 1,000,000,000?
- Problem: A grid holds oranges: 2 = rotten, 1 = fresh, 0 = empty: [[2,1,1],[1,1,0],[0,1,1]]. Each minute every fresh orange adjacent…