Data Structures & AlgorithmsModerateTCS NQT · counting

Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code.

Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code.
print(sum(1 for x in range(1000, 10000) if x % 11 == 0))
What is printed?
  1. A. 818
  2. B. 819
  3. C. 909
  4. D. 90

Correct answer: B. 819

floor(9999 / 11) - floor(999 / 11) = 909 - 90 = 819. Counting from 1 to 9999 instead gives 909.

More Coding Interview Problems questions

Exams that ask this topic