Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of the decimal digits of 9^9?

Problem: What is the sum of the decimal digits of 9^9?
print(sum(int(c) for c in str(9 ** 9)))
What is printed?
  1. A. 0
  2. B. 27
  3. C. 9
  4. D. 45

Correct answer: D. 45

9 ** 9 = 387420489, whose digits sum to 45. Writing 9 ^ 9 in Python is XOR and gives 0, mixing it up with 9! = 362880 gives 27, and the digital-root shortcut only says the sum is a multiple of 9 (repeatedly summing gives 9).

More Coding Interview Problems questions

Exams that ask this topic