Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 1000] are divisible by 7, 11 or 13? Run the code.
Problem: How many integers in [1, 1000] are divisible by 7, 11 or 13? Run the code.
print(sum(1 for x in range(1, 1001) if x % 7 == 0 or x % 11 == 0 or x % 13 == 0))What is printed?
- A. 308
- B. 280
- C. 252
- D. 220
Correct answer: B. 280
Inclusion-exclusion: 142 + 90 + 76 − (14 + 10 + 6) + 0 = 280. Skipping the overlaps gives 308, subtracting them twice gives 252, and forgetting 13 entirely gives 220.
More Coding Interview Problems questions
- Problem: What is the number of trailing zeros in 2025! (in decimal)? Run the code. python n = 2025 c = 0 p = 5 while p <= n: c += n // p p…
- Problem: What is the sum of all distinct prime factors of 2025? Run the code. python n = 2025 f = 2 ps = set() while f f <= n: while n % f…
- Problem: How many integers x in [1, 500] have x^2 + x + 41 prime? Run the code. python def isp(n): return n > 1 and all(n % d for d in…
- Problem: What is the length of the longest subarray of [2, 4, 6, 3, 8, 10, 12] whose elements are all even? Run the code. python a = [2…
- Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code. python print(len({100 // i for i in range(1…
- Problem: What is the number of ways to write 20 as an ordered sum of the parts 1 and 2 (compositions)? Run the DP. python f = [1, 1] for i…