Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 300] are divisible by exactly two of the numbers 2, 3 and 5? Run the code.
Problem: How many integers in [1, 300] are divisible by exactly two of the numbers 2, 3 and 5? Run the code.
print(sum(1 for x in range(1, 301) if sum(1 for d in (2, 3, 5) if x % d == 0) == 2))What is printed?
- A. 80
- B. 100
- C. 90
- D. 70
Correct answer: D. 70
Pairs: 6 → 50, 10 → 30, 15 → 20, minus 3 × 10 multiples of 30 that fall in all three, so 70. 'At least two' gives 80, the raw pairwise sum is 100, and subtracting the triple once gives 90.
More Coding Interview Problems questions
- Problem: What is the minimum number of perfect cubes (1, 8, 27, ...) that sum to 100? Run the DP. python INF = 10 9 dp = [0] + [INF] 100…
- Problem: How many integers in [1, 200] have an even number of 1-bits in their binary form? Run the code. python print(sum(1 for x in…
- Problem: What is the length of the longest subarray of [1, 1, 0, 1, 1, 1, 0, 1] containing at most one zero? Run the sliding-window code…
- Problem: How many distinct products a b arise when a and b are each a face value from 1 to 6? Run the code. python print(len({a b for a in…
- Problem: How many subsets of {1, 2, ..., 6} have a product that is a perfect square? Run the code (the empty set has product 1). python…
- Problem: What is the number of distinct values of floor(n / 2) + floor(n / 3) for 1 <= n <= 50? Run the code. python print(len({n // 2 + n…