Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many distinct values does floor(30 / i) take for i = 1 to 30?
Problem: How many distinct values does floor(30 / i) take for i = 1 to 30?
print(len({30 // i for i in range(1, 31)}))What is printed?- A. 11
- B. 10
- C. 8
- D. 5
Correct answer: B. 10
The distinct values of 30 // i are 30, 15, 10, 7, 6, 5, 4, 3, 2, 1: 10 of them, at most about 2√n. Rounding 2√30 ≈ 10.95 up gives 11, counting the divisors of 30 gives 8, and listing only the quotients for i ≤ √30 gives 5.
More Coding Interview Problems questions
- Problem: How many steps does Euclid's algorithm take on (2024, 748) before the remainder becomes 0? python a, b = 2024, 748 steps = 0…
- Problem: What is the sum of the divisors of 28 (a perfect number)? python print(sum(d for d in range(1, 29) if 28 % d == 0)) What is…
- Problem: How many pairs (i < j) of [1, 2, 3, 4, 5, 7] have an odd product? python a = [1, 2, 3, 4, 5, 7] print(sum(1 for i in…
- Problem: What is the total number of set bits in the binary representations of 1 through 100? python print(sum(bin(i).count('1') for i in…
- Problem: What is the minimum number of jumps needed to reach the last index of [1, 2, 1, 1, 1] when a[i] is the maximum jump length from…
- Problem: What is the number of trailing zeros of 1000!? python n = 1000 c = 0 p = 5 while p <= n: c += n // p p = 5 print(c) What is…