Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: What is the number of distinct values of floor(n / 2) + floor(n / 3) for 1 <= n <= 50? Run the code.

Problem: What is the number of distinct values of floor(n / 2) + floor(n / 3) for 1 <= n <= 50? Run the code.
print(len({n // 2 + n // 3 for n in range(1, 51)}))
What is printed?
  1. A. 41
  2. B. 34
  3. C. 43
  4. D. 50

Correct answer: B. 34

The set of n//2 + n//3 for n = 1..50 has 34 values; some jumps skip values. 41 assumes every value up to the maximum is hit, 43 adds the distinct counts of n//2 and n//3 separately, and 50 assumes one value per n.

More Coding Interview Problems questions

Exams that ask this topic