Data Structures & AlgorithmsModerateTCS NQT · basics

Problem: What is the sum of the digits of 2^10 = 1024? Run the code.

Problem: What is the sum of the digits of 2^10 = 1024? Run the code.
print(sum(int(c) for c in str(2 ** 10)))
What is printed?
  1. A. 6
  2. B. 8
  3. C. 10
  4. D. 7

Correct answer: D. 7

1 + 0 + 2 + 4 = 7. Summing the digits of 2^9 instead would give 8, a small slip to avoid.

More Coding Interview Problems questions

Exams that ask this topic