Data Structures & AlgorithmsModerateTCS NQT · basics

Problem: What is the sum of the decimal digits of 2^15? Run the code.

Problem: What is the sum of the decimal digits of 2^15? Run the code.
print(sum(int(c) for c in str(2 ** 15)))
What is printed?
  1. A. 25
  2. B. 26
  3. C. 22
  4. D. 5

Correct answer: B. 26

2¹⁵ = 32768, and 3 + 2 + 7 + 6 + 8 = 26. Using 2¹⁶ = 65536 gives 25, 2¹⁴ = 16384 gives 22, and 2⁵ = 32 gives 5.

More Coding Interview Problems questions

Exams that ask this topic