Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code.

Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code.
print(sum(x for x in range(1, 201) if x % 2 == 1 and x % 5 == 0))
What is printed?
  1. A. 4100
  2. B. 2000
  3. C. 2100
  4. D. 20

Correct answer: B. 2000

Odd multiples of 5 are 5, 15, …, 195: 20 terms averaging 100, total 2000. All multiples of 5 sum to 4100, the even ones (10..200) to 2100, and 20 is the count.

More Coding Interview Problems questions

Exams that ask this topic