Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of the digits of 3^20? Run the code.

Problem: What is the sum of the digits of 3^20? Run the code.
print(sum(int(c) for c in str(3 ** 20)))
What is printed?
  1. A. 36
  2. B. 45
  3. C. 27
  4. D. 10

Correct answer: B. 45

3²⁰ = 3486784401, whose digits sum to 45. 3¹⁹ gives 36, 3²¹ gives 27, and 10 is the number of digits.

More Coding Interview Problems questions

Exams that ask this topic