Data Structures & AlgorithmsHardTCS NQT · counting
Problem: How many integers from 1 to 1000 are divisible by 3 or by 5 but not by both?
- A. 467
- B. 401
- C. 533
- D. 400
Correct answer: B. 401
Multiples of 3 or 5 number 333 + 200 - 66 = 467, and removing the 66 multiples of 15 (divisible by both) leaves 401. Forgetting to remove the overlap gives the trap 467.
More Coding Interview Problems questions
- Problem: What is the product of the distinct prime factors of 360? Run the code. python n = 360 p, prod = 2, 1 while p p <= n: if n % p ==…
- Problem: What is the sum of all primes up to 50? Run the code. python print(sum(p for p in range(2, 51) if all(p % d for d in range(2…
- Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code. python n, k = 20, 10 C = [[0] (k +…
- Problem: How many distinct palindromes can be formed by rearranging the letters of 'aabb' (distinct strings, all letters used)? Run the…
- Problem: What is the minimum number of deletions to make the string 'abcca' a palindrome? Use the palindromic-subsequence DP and print…
- Problem: Find the next lexicographic permutation of the digits '1243' (the smallest permutation strictly greater than it). Run the code…