Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code.

Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code.
print(len({100 // i for i in range(1, 101)}))
What is printed?
  1. A. 20
  2. B. 10
  3. C. 19
  4. D. 100

Correct answer: C. 19

Values of 100 // i for i ≤ 10 are 10 distinct numbers, and for i > 10 the quotient takes the 9 values 1..9, total 19. The 2√n estimate gives 20, stopping at i = 10 gives 10, and real division gives 100.

More Coding Interview Problems questions

Exams that ask this topic