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?
  1. A. 11
  2. B. 10
  3. C. 8
  4. 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

Exams that ask this topic