Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: What is the sum of all two-digit numbers that are divisible by the sum of their digits? Run the code.

Problem: What is the sum of all two-digit numbers that are divisible by the sum of their digits? Run the code.
print(sum(x for x in range(10, 100) if x % sum(map(int, str(x))) == 0))
What is printed?
  1. A. 23
  2. B. 1077
  3. C. 1122
  4. D. 45

Correct answer: B. 1077

23 two-digit numbers (10, 12, 18, 20, 21, 24, …, 90) are divisible by their digit sum and add up to 1077. 23 is the count, including 1..9 gives 1122, and 45 is just 1 + … + 9.

More Coding Interview Problems questions

Exams that ask this topic